qq_44736946 2021-01-29 16:57 采纳率: 0%
浏览 86

Unity 同一个脚本摧毁一个gameobject的时候把其他的也摧毁了?

MissingReferenceException: The object of type 'ParticleSystem' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
UnityEngine.ParticleSystem.Play () (at <b15e40864454407eae445b174d810200>:0)
RubyController.ChangeHealth (System.Int32 amount) (at Assets/Scripts/RubyController.cs:129)
HealthCollectible.OnTriggerEnter2D (UnityEngine.Collider2D other) (at Assets/Scripts/HealthCollectible.cs:17)



吃草莓回血但是吃第二个草莓的时候出错了


几个草莓是同一个prefab, 挂的是同一个脚本

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class HealthCollectible : MonoBehaviour
{
    public AudioClip collectedClip;
    
    void OnTriggerEnter2D(Collider2D other)
    {
        RubyController controller = other.GetComponent<RubyController>();

        if (controller != null)
        {
            if (controller.health < controller.maxHealth)
            {
            	controller.ChangeHealth(1);
            	Destroy(gameObject);
            
            	controller.PlaySound(collectedClip);
            }
        }

    }
}




似乎是Destroy的时候把其他的草莓也摧毁了? 怎么办

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?
    • ¥15 c++头文件不能识别CDialog