My code is shown above. I place the game object Zap into that variable slot and then i get the error "The name ‘Zap’ does not denote a valid type (‘not found’)
Why would you guys want him to declare it as a new gameObject when it’s obviously a public variable? Just be sure since your variable is public, you assign the gameObject in the inspector, then check that it’s not null before you destroy it.
#pragma strict
var Zap : GameObject;
function Start()
{
if(Zap != null)
Destroy(Zap.gameObject);
}
zap must not actually be equal to anything it must be null already.
basically if you do for example
Zap : GameObject = new GameObject();
then
Destroy(Zap)
or you assign Zap through the editor window to something it’ll work
but basically what you need to understnad is declaring a variable doesnt make it equal to something or do anything nessacarily.
It’s confusing because some objects like numbers have a built in constructor so when you do for example
int x;
x actually exists now it is in fact a number with its default value which happens to be 0
thats coded in, when an int is created it automagically has a value
but not all classes do except a few intergral classes things like gameobjects require the new keyword to be assigned memory.