【发布时间】:2016-03-27 19:47:37
【问题描述】:
我正在通过烟雾粒子扑灭火焰粒子,所以我想检查对象是否被破坏,如果对象被破坏然后加载新场景。 这是我的脚本,,,,,,有什么建议吗?
using UnityEngine;
using System.Collections;
public class hey : MonoBehaviour {
void Start(){
GetComponent<ParticleSystem> ().emissionRate = 0;
}
void Update(){
if (Input.GetMouseButtonDown (1)) {
GetComponent<ParticleSystem> ().Emit (20);
}
}
void OnParticleCollision(GameObject obj)
{
Destroy (obj, 2.0f);
//here i want to check and then load new scene..
//I try that thing, but failed..nothing happen
if (object.Equals (obj, null)) {
Application.LoadLevel (7);
}
//also this one, but nothing happens
if(gameObject.tag=="fire123"==null){
Application.LoadLevel (7);
}
// also this one too, but failed :-(
void OnDestroy(){
Application.LoadLevel (7); } }
【问题讨论】:
-
你试过没有
Destroy的时间吗?这可能是问题所在。当你到达 if 时,它还没有被破坏。尝试使其成为协程可能会有所帮助(并使用waitForSeconds)。 -
@GunnarB。是的,我不这么认为,好吧,让我试试。感谢您的评论:-)
-
@GunnarB。非常感谢它对我有用..请将其发布到答案标签中,我会评价它有帮助。
-
类名必须有大写字母,所以干草不是干草
-
@JoeBlow Wao,你刚刚发现了什么错误......?请坚持这一点,无论如何我都在干我的代码并且错误与类名无关,我知道如何编写类名(所有约定),而你甚至没有正确读取名称..它嘿,不是海...