The Problem: > I am trying to use .actions in the image but instead VS cannot identify ".actions".
What I’ve Tried:
Looking everywhere in the inspector for if anything related to the Player Input component (the input action asset)
I've tried removing it, but another error appears, saying that i must refer to a gameobject, even though im not.
Relevant Code/Setup:
Engine: Unity 6000.3.10f1 (windows)
Script:
1 using UnityEngine;
2 using UnityEngine.InputSystem;
3
4 public class PlayerBehaviour : MonoBehaviour
5 {
6 PlayerInput playerInput;
7 InputAction moveAction;
8
9 [SerializeField] float playerSpeed;
10
11 // Start is called once before the first execution of Update after the MonoBehaviour is created
12 void Start()
13 {
14 playerInput = GetComponent<PlayerInput>();
15 moveAction = playerInput.actions.FindAction("Walking");
16 }
17
18 // Update is called once per frame
19 void Update()
20 {
21 MovePlayer();
22 }
23
24 void MovePlayer()
25 {
26 Debug.Log(moveAction.ReadValue<Vector2>());
27 //Vector2 direction = moveAction.ReadValue<Vector2>();
28 //transform.position += new Vector3(direction.x, 0, direction.y) * Time.deltaTime * playerSpeed;
29 }
30 }
Console Errors:
i)Assets\Scripts\PlayerBehaviour.cs(15,34): error CS1061: 'PlayerInput' does not contain a definition for 'actions' and no accessible extension method 'actions' accepting a first argument of type 'PlayerInput' could be found (are you missing a using directive or an assembly reference?)
ii [if i remove .actions])NullReferenceException: Object reference not set to an instance of an object
PlayerBehaviour.MovePlayer () (at Assets/Scripts/PlayerBehaviour.cs:26)
PlayerBehaviour.Update () (at Assets/Scripts/PlayerBehaviour.cs:21)