Why does Unity give me an CS0246 error on behalf of "Action"?

Advertisements

Me and some friends are working on a unity game and stumbled across an error in the main movement script.Can any of you guys help me? This is the code of the movement script.I have problems with the 1st and 2nd error as the 3rd with duplicate variables has been fixed.I used his tutorials for the game.
Image of the error messages

using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.UI;
using UnityEngine.Events;

public class Player : MonoBehaviour{
[SerializeField] float mouseSensitivity=3f;
[SerializeField] float movementSpeed=5f;
[SerializeField] float mass=1f;
[SerializeField] float acceleration=20f;
[SerializeField] Transform cameraTransform;

public event Action OnBeforeMove;

internal float movementSpeedMultiplier;

public bool IsGrounded=>controller.isGrounded;
public event Action<bool> OnGroundStateChange;
internal float movementSpeedMultiplier;
CharacterController controller;
internal Vector3 velocity;
Vector2 look;
bool wasGrounded;

PlayerInput playerInput;
InputAction moveAction;
InputAction lookAction;
InputAction sprintAction;

void Awake(){
    controller=GetComponent<CharacterController>();
    playerInput=GetComponent<PlayerInput>();
    moveAction=playerInput.actions["move"];
    lookAction=playerInput.actions["look"];
    sprintAction=playerInput.actions["sprint"];
}

void Start(){
    Cursor.lockState=CursorLockMode.Locked; //Locks Cursor//
}

void Update(){
    UpdateGround();
    UpdateGravity();
    UpdateMovement();
    UpdateLook();
}

void UpdateGround(){
   if(wasGrounded!=IsGrounded){
       OnGroundStateChange?.Invoke();
       wasGrounded=IsGrounded;
   }
}

void UpdateGravity(){
    var gravity=Physics.gravity*mass*Time.deltaTime;
    velocity.y=controller.isGrounded?-1f:velocity.y+gravity.y;
}

Vector3 GetMovementInput(){
    var moveInput=moveAction.ReadValue<Vector2>();
    var input=new Vector3();
    input+=transform.forward*moveInput.y;
    input+=transform.right*moveInput.x;
    input=Vector3.ClampMagnitude(input,1f);
    input*=movementSpeed*movementSpeedMultiplier;
    return input;
}

void UpdateMovement(){
    movementSpeedMultiplier=1f;
    OnBeforeMove?.Invoke();
    var input=GetMovementIput();

    var factor=acceleration*Time.deltaTime;
    velocity.x=Mathf.Lerp(velocity.x,input.x,factor);
    velocity.z=Mathf.Lerp(velocity.z,input.z,factor);

    controller.Move(velocity*Time.deltaTime);

}

void UpdateLook(){
    var lookInput=lookAction.ReadValue<Vector2>();
    look.x+=lookInput.x*mouseSensitivity;
    look.y+=lookInput.y*mouseSensitivity;

    look.y=Mathf.Clamp(look.y,-89f,89f);

    //Debug.Log(look);//
    
    cameraTransform.localRotation=Quaternion.Euler(-look.y,0,0);
    transform.localRotation=Quaternion.Euler(0,look.x,0);
}
}

I will also link the error messages

>Solution :

You are missing using System;, add it to the top of the file. The Action delegate family (Action, Action<T>, etc.) comes from the System namespace.

Leave a ReplyCancel reply