- Home /
Instantiated object isnt moving
So i`ve written a simple script that instantiates object, and moves this object by equaling position, but it isnt moving . Thanks!
   void Update() 
     {    
           Timer-=Time.deltaTime;
         if(Timer<=0 && instantiated == false)
         {
         Instantiate(wave,transform.position,Quaternion.Euler(-90,0,0));
             instantiated = true;
         }
         if(wave != null)
         {
             wave.transform.position = new Vector3(transform.position.x,transform.position.y,transform.position.z);
         }
           transform.Translate(Vector3.forward * Time.deltaTime * speed);            
     }
Put some debug.log between each steps to see how it goes, then you will find what's wrong.
I think issue is in this line wave.transform.position = new Vector3(transform.position.x,transform.position.y,transform.position.z); but i dont understand why?
Answer by amphoterik · Jul 26, 2013 at 11:36 AM
Wave is just the name of your prefab. You need to actually get a reference to the object you create:
 Transform newWave =(Transform)Instantiate(wave,transform.position,Quaternion.Euler(-90,0,0));
Then you can modify this however you need:
 if(newWave != null)
 {
     newWave.position = new Vector3(transform.position.x,transform.position.y,transform.position.z);
 }
I think logic of oyur code is right, but i get error in this line:GameObject newWave =(GameObject)Instantiate(wave,transform.position,Quaternion.Euler(-90,0,0));: InvalidCastException: Cannot cast from source type to destination type.
Your answer
 
 
             Follow this Question
Related Questions
Vector3 of moving object always returns (0,0,0) 1 Answer
Problem with a motion script 0 Answers
Sum Of Two Motions? 0 Answers
2D get touch input 1 Answer
Vector3 Transform.Position Not Working 2 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                