C# cant find a unity auto generated class

北城余情 提交于 2021-02-16 15:07:31

问题


Okay so I'm learning to use the new InputActions and I've created a C# scripts using

https://prnt.sc/oyaj5l

And this is what I got:

// GENERATED AUTOMATICALLY FROM 'Assets/PlayerControls.inputactions'

using System.Collections;
using System.Collections.Generic;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Utilities;

public class PlayerControls : IInputActionCollection
{
    private InputActionAsset asset;
    public PlayerControls()
    {
        ///
    }
}

But when I try to create an PlayerControls object, I get an error saying

The type or namespace name 'PlayerControls' could not be found (are you missing a using directive or an assembly reference?)

This is the class where I try to reference it:

using System;
using UnityEngine;
using System.Collections;
using UnityStandardAssets.CrossPlatformInput;
using UnityStandardAssets.Utility;
using Random = UnityEngine.Random;
using UnityEngine.InputSystem;

namespace UnityStandardAssets.Characters.FirstPerson
{
    public class FirstPersonController : MonoBehaviour
    {
        private PlayerControls controls; // ERROR HERE
    }
}

回答1:


Wrap the PlayerControls class in a namespace, then add a using statement in your class that points to the namespace where your PlayerControls class lives.




回答2:


I solved it! It looks like Unity has a compile order. I referenced this: http://answers.unity.com/answers/1274460/view.html and managed to solve it after seeing that "Standard Assets" has priority over other assets



来源:https://stackoverflow.com/questions/57680427/c-sharp-cant-find-a-unity-auto-generated-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!