Reputation:
I'm getting error on second line with this code:
var myNewSmoke = Instantiate (cube, temp, transform.rotation);
myNewSmoke.transform.parent = gameObject.transform;
error:
Type
UnityEngine.Object
does not contain a definition fortransform
and no extension methodtransform
of typeUnityEngine.Object
could be found (are you missing a using directive or an assembly reference?)
I don't understand the error. What's the problem?
Upvotes: 0
Views: 66
Reputation: 1825
Instantiate is a method of Object Class. You're trying to access gameobject.transform
which is inside GameObject Class.
GameObject Class Implements Object Class like everything else so you have to cast it into GameObject first.
var myNewSmoke = Instantiate (cube, temp, transform.rotation) as GameObject;
Or
GameObject myNewSmoke = Instantiate (cube, temp, transform.rotation) as GameObject;
Upvotes: 1