Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法修复Unity中的单行为脚本问题_C#_Unity3d - Fatal编程技术网

C# 无法修复Unity中的单行为脚本问题

C# 无法修复Unity中的单行为脚本问题,c#,unity3d,C#,Unity3d,我刚刚开始使用Unity并使用它的标准资产库。我使用了它的RolleBall对象,但它的Ball和BallUserControl脚本都给了我以下错误: 文件中没有MonoBehavior脚本,或者名称与文件名不匹配 我没有更改任何脚本,并且我的环境中没有其他对象或脚本。类名与文件名匹配。我肯定我错过了一些明显的东西(太新了)。有哪些可能的错误? 我正在windows 10上运行最新版本的unity 以下是BallUserControl脚本,请参见: using System; using Uni

我刚刚开始使用Unity并使用它的标准资产库。我使用了它的RolleBall对象,但它的Ball和BallUserControl脚本都给了我以下错误:

文件中没有MonoBehavior脚本,或者名称与文件名不匹配

我没有更改任何脚本,并且我的环境中没有其他对象或脚本。类名与文件名匹配。我肯定我错过了一些明显的东西(太新了)。有哪些可能的错误? 我正在windows 10上运行最新版本的unity

以下是BallUserControl脚本,请参见:

using System;
using UnityEngine;
using UnityStandardAssets.CrossPlatformInput;

namespace UnityStandardAssets.Vehicles.Ball
{
    public class BallUserControl : MonoBehaviour
    {
        private Ball ball; // Reference to the ball controller.

        private Vector3 move;
        // the world-relative desired move direction, calculated from the camForward and user input.

        private Transform cam; // A reference to the main camera in the scenes transform
        private Vector3 camForward; // The current forward direction of the camera
        private bool jump; // whether the jump button is currently pressed


        private void Awake()
        {
            // Set up the reference.
            ball = GetComponent<Ball>();


            // get the transform of the main camera
            if (Camera.main != null)
            {
                cam = Camera.main.transform;
            }
            else
            {
                Debug.LogWarning(
                    "Warning: no main camera found. Ball needs a Camera tagged \"MainCamera\", for camera-relative controls.");
                // we use world-relative controls in this case, which may not be what the user wants, but hey, we warned them!
            }
        }


        private void Update()
        {
            // Get the axis and jump input.

            float h = CrossPlatformInputManager.GetAxis("Horizontal");
            float v = CrossPlatformInputManager.GetAxis("Vertical");
            jump = CrossPlatformInputManager.GetButton("Jump");

            // calculate move direction
            if (cam != null)
            {
                // calculate camera relative direction to move:
                camForward = Vector3.Scale(cam.forward, new Vector3(1, 0, 1)).normalized;
                move = (v*camForward + h*cam.right).normalized;
            }
            else
            {
                // we use world-relative directions in the case of no main camera
                move = (v*Vector3.forward + h*Vector3.right).normalized;
            }
        }


        private void FixedUpdate()
        {
            // Call the Move function of the ball controller
            ball.Move(move, jump);
            jump = false;
        }
    }
}
使用系统;
使用UnityEngine;
使用UnityStandardAssets.CrossPlatformInput;
命名空间UnityStandardAssets.Vehicles.Ball
{
公共类BallUserControl:单行为
{
private Ball;//对球控制器的引用。
私人向量3移动;
//根据camForward和用户输入计算的世界相对所需移动方向。
私有变换cam;//场景变换中对主摄影机的引用
private Vector3 camForward;//相机的当前前进方向
private bool jump;//当前是否按下了跳转按钮
私人空间
{
//设置引用。
ball=GetComponent();
//获取主摄影机的变换
如果(Camera.main!=null)
{
cam=Camera.main.transform;
}
其他的
{
Debug.LogWarning(
“警告:找不到主摄像机。球需要一个标记为“主摄像机”的摄像机,用于摄像机相对控制。”);
//在这种情况下,我们使用世界相对控件,这可能不是用户想要的,但是,嘿,我们警告过他们!
}
}
私有void更新()
{
//获取轴和跳转输入。
float h=CrossPlatformInputManager.GetAxis(“水平”);
float v=CrossPlatformInputManager.GetAxis(“垂直”);
跳转=CrossPlatformInputManager.GetButton(“跳转”);
//计算移动方向
如果(cam!=null)
{
//计算要移动的相机相对方向:
camForward=Vector3.比例(cam.forward,新的Vector3(1,0,1))。标准化;
移动=(v*camForward+h*cam.right)。标准化;
}
其他的
{
//在没有主摄像机的情况下,我们使用世界相对方向
move=(v*Vector3.forward+h*Vector3.right)。标准化;
}
}
私有void FixedUpdate()
{
//调用球控制器的移动功能
球。移动(移动,跳跃);
跳跃=假;
}
}
}

上传BallUserControl脚本更新了我的问题以包含脚本。如果您还需要什么,请告诉我您使用的是哪个Unity版本?资产是否与其兼容?他们说我没有犯那个错误。我从unity内部导入了资产。我使用的是2019.3.0a7版本。不必与问题直接相关,但一般来说:是alpha版本(因此小
a
)。与任何其他alpha版本一样,它只用于测试新功能,不适合生产。它不太可能充满小错误和bug。。这就是拥有alpha和beta版本的全部目的。签出该页上的
已知问题
部分。如果你真的想使用Unity来创建一些东西,请坚持使用最新的稳定版本-当前为
2019.1.8
。上传BallUserControl脚本更新我的问题以包含脚本。如果您还需要什么,请告诉我您使用的是哪个Unity版本?资产是否与其兼容?他们说我没有犯那个错误。我从unity内部导入了资产。我使用的是2019.3.0a7版本。不必与问题直接相关,但一般来说:是alpha版本(因此小
a
)。与任何其他alpha版本一样,它只用于测试新功能,不适合生产。它不太可能充满小错误和bug。。这就是拥有alpha和beta版本的全部目的。签出该页上的
已知问题
部分。如果你真的想用Unity来创建一些东西,请坚持使用最新的稳定版本-当前为
2019.1.8