I am doing the 2D adventure game course and I’m having some issues with using Input Actions I try to implament it in my code and I’m just getting a bunch of errors and I’m not sure what I’m doing wrong.
tusing System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerController : MonoBehaviour
{
public InputAction LeftAction;
// Start is called before the first frame update
void Start()
{
LeftAction.Enable();
}
// Update is called once per frame
void Update()
{
float horizontal = 0.0f;
float vertical = 0.0f;
if (LeftAction.isPressed())
{
horizontal = -1.0f;
}
else if (Keyboard.current.rightArrowKey.isPressed)
{
horizontal = 1.0f;
}
if (Keyboard.current.upArrowKey.isPressed)
{
vertical = 1.0f;
}
else if (Keyboard.current.downArrowKey.isPressed)
{
vertical = -1.0f;
}
Debug.Log(horizontal);
Debug.Log(vertical);
Vector2 position = transform.position;
position.x = position.x + 0.1f * horizontal;
position.y = position.y + 0.1f * vertical;
transform.position = position;
}
}
Here is the code in it’s entirety I’m just not sure what I’m doing wrong as I’m trying to follow it to a T just to figure it out.