【问题标题】:Unity does not even recognize "Collider" on my function "OnTriggerEnter()"Unity 甚至无法识别我的函数“OnTriggerEnter()”上的“Collider”
【发布时间】:2019-07-15 09:43:30
【问题描述】:

我是 Unity 初学者,所以现在我正在通过观看 youtube 上的一些教程来做一些小项目。 但是,在查看了一个使用“OnTriggerEnter”函数和“Collider”属性的教程之后。我意识到我的编辑器无法识别“Collider”,所以我无法使用“OnTriggerEnter”。

我在互联网上搜索,但找不到与我的问题相关的任何答案。 第一次遇到这种情况,不知道怎么解决。。。

这是我的小代码,当我的玩家进入一个区域时,我只是想移动一些东西。

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

public class Trigger : MonoBehaviour
{

    public bool opening = false;

    // Start is called before the first frame update
    void Start()
    {

    }

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

    }

    // OnTriggerEnter is called when something enter in the trigger
    void OnTriggerEnter(Collider obj)
    {
        if(obj.transform.name == "Player")
        {
            opening = true;
        }
    }
}

所以,正如我所说,我的统一编辑器是 Microsoft Visual Studio 没有检测到“碰撞器”(例如,我无法通过按 Enter 进行预填充)并且颜色是白色而不是蓝色以“真”为例。 因此,我无法继续进行该项目,我想知道该怎么做才能让我的编辑识别“Collider”并且我可以使我的项目工作!

提前感谢您的回答。

【问题讨论】:

    标签: c# visual-studio unity3d


    【解决方案1】:

    要解决这个问题,您可以执行以下操作:

    1. 关闭 Unity 和 Visual Studio。
    2. 开放统一。
    3. 从 Unity 打开 Visual Studio(资产 => 打开 C# 项目)。

    如果这不起作用,您需要检查您当前的编辑器:
    Edit => Preferences => External Tools => External Script Editor

    【讨论】:

    • 好的,谢谢,已经好多了!但问题是我的编辑器没有捕捉到统一 api,因此不能给我任何关于我编码的信息!比如给我方法等等……
    【解决方案2】:

    Visual Studio 总是有一些错误,比如缺少依赖项和东西。我会推荐使用 Visual Studio Code 应用程序。就像@Jack 解释的那样。浏览到 Edit => Preferences => External Tools => External Script Editor 并将脚本编辑器更改为 Visual Studio Code,然后重试。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-10-22
      • 1970-01-01
      • 2012-01-04
      • 1970-01-01
      • 1970-01-01
      • 2014-12-10
      • 1970-01-01
      相关资源
      最近更新 更多