首页 > 解决方案 > Unity 不会执行脚本

问题描述

这是我统一的超级简单脚本:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class script : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        Debug.Log("Something");
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}

我将脚本附加到主摄像机:

main_camera_properties


在我运行统一游戏后,控制台是empty,这意味着脚本不会运行。


这只是我创建的一个新项目来测试它,因为在我的原始项目中,unity 自发地停止执行脚本。我卸载了旧版本(2019)并安装了新版本(2020)以及 Visual Studio(即使没有必要),但没有任何区别。

标签: unity3dconsoleexecution

解决方案


您提供的代码似乎工作正常。控制台窗口为空的一个潜在原因可能是由于搜索字段中有某些内容或禁用了标准日志。

在此处输入图像描述


推荐阅读