未分配的引用异常,Unity [英] Unassigned Reference Exception, Unity
问题描述
public GameObject RIPEnemigo;
void Rekt()
{
GameObject RIP = (GameObject)Instantiate(RIPEnemy, transform.position, transform.rotation); //Instantiate of the particles
Destroy(gameObject); //Destroys enemy
Destroy(RIP, 2f); //Destroys particles
}
我添加了粒子预制件,检查器中的一切正常,但它说:
I added the particles prefab and everything in the inspector is OK, but it says:
UnassignedReferenceException: Bullet 的变量 RIPEnemy 尚未分配
UnassignedReferenceException: The variable RIPEnemy of Bullet has not been assigned
您可能需要在检查器中分配 Bullet 脚本的 RIPEnemy 变量.
You probably need to assign the RIPEnemy variable of the Bullet script in the inspector.
RIPEnemy
是粒子效果
为什么?这很容易,当敌人被击中时 ->粒子->RIP 敌人 ->RIP 粒子.我在论坛中搜索过,但我不明白我的错误在哪里
Why? It's easy, when enemy gets hit -> particles -> RIP Enemy -> RIP Particles. I've searched in the forum but I don't understand where's my error
推荐答案
看你的代码我相信,假设你在检查器中或通过代码分配了 RIPEnemigo,行
Looking at your code I believe that, assuming you assigned RIPEnemigo in the inspector or by code, the line
GameObject RIP = (GameObject)Instantiate(RIPEnemy, transform.position, transform.rotation);
应该是
GameObject RIP = (GameObject)Instantiate(RIPEnemigo, transform.position, transform.rotation);
那应该可以解决您的问题.
That should fix your problem.
这篇关于未分配的引用异常,Unity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!