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的时候把其他的草莓也摧毁了? 怎么办