我試圖檢測玩家的角色控制器何時接觸到名為“水”的游戲物件,但我收到錯誤訊息“當前背景關系中不存在名稱‘碰撞’。”
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,但沒有奏效。
uj5u.com熱心網友回復:
將您的方法更改為此,它將再次起作用;
public void OnControllerColliderHit(ControllerColliderHit collision)
{
if (collision.gameObject.tag == "Water")
{
Debug.Log("it worked!!");
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/528959.html
