unity3d Unity 3d / C#错误CS 0103“名称'collision'在当前上下文中不存在”[已关闭]

oknwwptz  于 2022-11-16  发布在  C#
关注(0)|答案(1)|浏览(175)

**已关闭。**此问题为not reproducible or was caused by typos。目前不接受答案。

这个问题是由一个打字错误或一个无法再重现的问题引起的。虽然类似的问题在这里可能是on-topic,但这个问题的解决方式不太可能帮助未来的读者。
2天前关闭。
Improve this question
我试图检测我的玩家的角色控制器何时接触到名为“water”的游戏对象,但我得到错误“The name 'collision' does not existed in the current context”。

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class PlayerTouched : MonoBehaviour
  5. {
  6. public void OnControllerColliderHit(ControllerColliderHit hit)
  7. {
  8. if (collision.gameObject.tag == "Water")
  9. {
  10. Debug.Log("it worked!!");
  11. }
  12. }
  13. }

我最初尝试使用OnCollisionEnter,但没有成功。

jslywgbw

jslywgbw1#

将您的方法更改为该方法,它将再次工作;

  1. public void OnControllerColliderHit(ControllerColliderHit collision)
  2. {
  3. if (collision.gameObject.tag == "Water")
  4. {
  5. Debug.Log("it worked!!");
  6. }
  7. }

相关问题