I’m currently making an ARPG, part of my script looks like this:
class SkillFireball extends MonoBehaviour{
var harmful:GameObject; // Drag the prefab of Fireball to this variable
function AimAndFire(){
Instantiate(harmful, pos, rot); //---- Line X -----
}
}
I know that I only write a small portion of code here, but the strange thing is:
-
There is no error nor warning in editor mode. And I’m sure I’ve Drag the prefab of Fireball to
var harmful
in Inspector window. -
The Windows executable file I built always occur errors at Line X: “argument exception: the prefab you want to instantiate is null”
After I changed my code to this, the problem solved.
class SkillFireball extends MonoBehaviour{
private var harmful:GameObject; // Drag the prefab of Fireball to this variable
function Awake(){
harmful=Resources.Load("SkillFireballHarmful", GameObject);
}
function AimAndFire(){
Instantiate(harmful, pos, rot); //---- Line X -----
}
}
But using Resources Class is hard for me to maintain, thus I’ve heard that it is less efficient.
Is there any idea why my first code don’t work?