【问题标题】:check object destroyed and load new scene检查对象被破坏并加载新场景
【发布时间】: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,你刚刚发现了什么错误......?请坚持这一点,无论如何我都在干我的代码并且错误与类名无关,我知道如何编写类名(所有约定),而你甚至没有正确读取名称..它嘿,不是海...

标签: object unity3d


【解决方案1】:

问题:Destroy(obj, **2.0f**); 由于延迟,在评估 if 时项目不会被破坏。

所以要么不使用延迟,要么将 OnParticleCollision 设为协程并使用 yield return new waitForSeconds 或将检查放在其他位置,如 Update 或在被销毁粒子的脚本中使用 OnDestroy

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-09-20
    • 1970-01-01
    • 2010-12-25
    • 2020-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多