这会引发错误,但对象实际上已实例化,并且一切按预期工作。无论我重现多少次,该错误都不会停止程序。
using UnityEngine;
public class BulletAttr : MonoBehaviour
{
public int damage;
public int speed;
public GameObject webPrefab;
private void OnTriggerEnter2D(Collider2D collider)
{
if (collider.tag == "Border")
{
Destroy(gameObject);
}
if (collider.tag == "Fish")
{
GameObject web = Instantiate(webPrefab);
web.transform.SetParent(gameObject.transform.parent, false);
web.transform.position = gameObject.transform.position;
Destroy(gameObject);
}
}
}
ArgumentException: The Object you want to instantiate is null.
UnityEngine.Object.CheckNullArgument (System.Object arg, System.String message) (at C:/buildslave/unity/build/Runtime/Export/UnityEngineObject.cs:239)
UnityEngine.Object.Instantiate[GameObject] (UnityEngine.GameObject original) (at C:/buildslave/unity/build/Runtime/Export/UnityEngineObject.cs:199)
BulletAttr.OnTriggerEnter2D (UnityEngine.Collider2D collider) (at Assets/Scripts/BulletAttr.cs:19)