【问题标题】:Unity 3d / C# Error CS0103 "The name 'collision' does not exist in the current context"Unity 3d / C# 错误 CS0103 \"当前上下文中不存在名称 \'collision\'"
【发布时间】:2022-11-04 05:09:15
【问题描述】:

我试图检测玩家的角色控制器何时接触到名为“水”的游戏对象,但我收到错误消息“当前上下文中不存在名称‘碰撞’。”

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

public class PlayerTouched : MonoBehaviour
{
    public void OnControllerColliderHit(ControllerColliderHit hit)

    {
        if (collision.gameObject.tag == "Water")
        {

            Debug.Log("it worked!!");
        }
    }
}

我最初尝试使用 OnCollisionEnter,但没有奏效。

【问题讨论】:

    标签: c# unity3d syntax-error character collision-detection


    【解决方案1】:

    将您的方法更改为此,它将再次起作用;

    public void OnControllerColliderHit(ControllerColliderHit collision)
    {
        if (collision.gameObject.tag == "Water")
        {
            Debug.Log("it worked!!");
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-05
      • 2021-02-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多