Hello, I keep getting the same error. Here are the scripts:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.AI;
public class PlayerController : MonoBehaviour
{
const string IDLE = "Idle";
const string WALK = "Walk";
CustomActions input;
NavMeshAgent agent;
Animator animator;
[Header("Movement")]
[SerializeField] ParticleSystem clickEffect;
[SerializeField] LayerMask clickableLayers;
float lookRotationSpeed = 8f;
void Awake()
{
agent = GetComponent<NavMeshAgent>();
animator = GetComponent<Animator>();
input = new CustomActions();
AssignInputs();
}
void AssignInputs()
{
input.Main.Move.performed += ctx => ClickToMove();
}
void ClickToMove()
{
RaycastHit hit;
if (Physics.Raycast(Camera.main.ScreenPointToRay(Mouse.current.position.ReadValue()), out hit, 100, clickableLayers))
{
agent.destination = hit.point;
if (clickEffect != null)
{
Instantiate(clickEffect, hit.point + new Vector3(0, 0.1f, 0), clickEffect.transform.rotation);
}
}
}
void OnEnable()
{
input.Enable();
}
void OnDisable()
{
input.Disable();
}
void Update()
{
FaceTarget();
SetAnimations();
}
void FaceTarget()
{
if (agent.velocity != Vector3.zero)
{
Vector3 direction = (agent.destination - transform.position).normalized;
Quaternion lookRotation = Quaternion.LookRotation(new Vector3(direction.x, 0, direction.z));
transform.rotation = Quaternion.Slerp(transform.rotation, lookRotation, Time.deltaTime * lookRotationSpeed);
}
}
void SetAnimations()
{
if (agent.velocity == Vector3.zero)
{
animator.Play(IDLE);
}
else
{
animator.Play(WALK);
}
}
}
//------------------------------------------------------------------------------
// <auto-generated>
// This code was auto-generated by com.unity.inputsystem:InputActionCodeGenerator
// version 1.7.0
// from Assets/Scripts/InputActions/CustomActions.inputactions
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Utilities;
public partial class @CustomActions: IInputActionCollection2, IDisposable
{
public InputActionAsset asset { get; }
public @CustomActions()
{
asset = InputActionAsset.FromJson(@"{
""name"": ""CustomActions"",
""maps"": [
{
""name"": ""Main"",
""id"": ""c848c822-a0a1-4832-91fa-7cc1438e02b7"",
""actions"": [
{
""name"": ""Move"",
""type"": ""Button"",
""id"": ""c5db34d4-0f4c-48a1-82d3-8b32a1fb6b9b"",
""expectedControlType"": ""Button"",
""processors"": """",
""interactions"": """",
""initialStateCheck"": false
}
],
""bindings"": [
{
""name"": """",
""id"": ""8a191a23-46c7-41bc-8bf0-20c4647c4fef"",
""path"": ""<Mouse>/leftButton"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""Move"",
""isComposite"": false,
""isPartOfComposite"": false
}
]
}
],
""controlSchemes"": []
}");
// Main
m_Main = asset.FindActionMap("Main", throwIfNotFound: true);
m_Main_Move = m_Main.FindAction("Move", throwIfNotFound: true);
}
public void Dispose()
{
UnityEngine.Object.Destroy(asset);
}
public InputBinding? bindingMask
{
get => asset.bindingMask;
set => asset.bindingMask = value;
}
public ReadOnlyArray<InputDevice>? devices
{
get => asset.devices;
set => asset.devices = value;
}
public ReadOnlyArray<InputControlScheme> controlSchemes => asset.controlSchemes;
public bool Contains(InputAction action)
{
return asset.Contains(action);
}
public IEnumerator<InputAction> GetEnumerator()
{
return asset.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
public void Enable()
{
asset.Enable();
}
public void Disable()
{
asset.Disable();
}
public IEnumerable<InputBinding> bindings => asset.bindings;
public InputAction FindAction(string actionNameOrId, bool throwIfNotFound = false)
{
return asset.FindAction(actionNameOrId, throwIfNotFound);
}
public int FindBinding(InputBinding bindingMask, out InputAction action)
{
return asset.FindBinding(bindingMask, out action);
}
// Main
private readonly InputActionMap m_Main;
private List<IMainActions> m_MainActionsCallbackInterfaces = new List<IMainActions>();
private readonly InputAction m_Main_Move;
public struct MainActions
{
private @CustomActions m_Wrapper;
public MainActions(@CustomActions wrapper) { m_Wrapper = wrapper; }
public InputAction @Move => m_Wrapper.m_Main_Move;
public InputActionMap Get() { return m_Wrapper.m_Main; }
public void Enable() { Get().Enable(); }
public void Disable() { Get().Disable(); }
public bool enabled => Get().enabled;
public static implicit operator InputActionMap(MainActions set) { return set.Get(); }
public void AddCallbacks(IMainActions instance)
{
if (instance == null || m_Wrapper.m_MainActionsCallbackInterfaces.Contains(instance)) return;
m_Wrapper.m_MainActionsCallbackInterfaces.Add(instance);
@Move.started += instance.OnMove;
@Move.performed += instance.OnMove;
@Move.canceled += instance.OnMove;
}
private void UnregisterCallbacks(IMainActions instance)
{
@Move.started -= instance.OnMove;
@Move.performed -= instance.OnMove;
@Move.canceled -= instance.OnMove;
}
public void RemoveCallbacks(IMainActions instance)
{
if (m_Wrapper.m_MainActionsCallbackInterfaces.Remove(instance))
UnregisterCallbacks(instance);
}
public void SetCallbacks(IMainActions instance)
{
foreach (var item in m_Wrapper.m_MainActionsCallbackInterfaces)
UnregisterCallbacks(item);
m_Wrapper.m_MainActionsCallbackInterfaces.Clear();
AddCallbacks(instance);
}
}
public MainActions @Main => new MainActions(this);
public interface IMainActions
{
void OnMove(InputAction.CallbackContext context);
}
}