【发布时间】:2020-04-04 13:26:56
【问题描述】:
我是编程新手,目前正在尝试在 Unity 中做一个简单的游戏。
代码使某些东西在接触地面时消失,并且运行良好,但 Unity Inspector 中的“Evaporated”变量没有更新。当有东西接触地面时,蒸发量应该增加,但它保持在0。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Threading;
public class EnemyEvaporate : MonoBehaviour
{
public GameObject Enemy;
public int Evaporated;
void OnCollisionEnter(Collision CollisionInfo)
{
if (CollisionInfo.gameObject.name == "Map" || CollisionInfo.gameObject.name == "Player")
{
Thread.Sleep(15);
gameObject.SetActive(false);
Evaporated++;
}
}
}
【问题讨论】:
-
嗨,在递增之前是否已蒸发初始化?代码路径是否执行? ("is one of the if's before true") 你有什么例外吗?
-
请注意,问题标题应描述您遇到的问题。 “无法弄清楚我做错了什么”没有说明这个问题是关于什么的。
-
初始化为0,代码执行没有任何问题。
-
约翰,谢谢你的建议,这是我在这个网站上的第一篇文章。
-
我看不出代码有什么问题,除了它可能没有运行。如果添加 Debug.Log("代码运行良好!"); if 语句中的行是否按您的预期显示?