Reputation: 4634
I'm working on a 2D Unity
game, and I want to create a Boom in run time and move it.
Here is part of my code.
I create a prefab
Boom, and I drop it into inspector.
public GameObject Boom; // prefab Boom is drop here
void OnMouseDown()
{
...
Vector3 NewBoomPostion = new Vector3 (Luncher.transform.position.x,BoomPosition, 85);
Instantiate(Boom, NewBoomPostion , Quaternion.identity);
iTween.MoveTo (Boom, iTween.Hash ("y",BoomendPosition ,"speed",Boomspeed,"EaseType",BoomeaseType,"LoopType",BoomloopType));
}
But it throws this error
NullReferenceException: Object reference not set to an instance of an object iTween.RetrieveArgs ()
Upvotes: 0
Views: 906
Reputation: 1076
I think problem is, Instantiate() instantiates a copy of object (Boom). After instantiate it, your new game object doesn't point to Boom object. It's a new game object.
GameObject instantiatedBoom = (GameObject) Instantiate (Boom, newBoomPosition, Quaternion.identity);
iTween.MoveTo( instantiatedBoom,....);
should solve it
Upvotes: 2