- Home /
 
               Question by 
               Persona · Dec 13, 2011 at 06:09 PM · 
                arraystargethomingstatic-vars  
              
 
              Why can't I set the Target
I'm trying to set the target of a homing shot after it's spawned when an enemy is hit by ray cast, but it doesn't work and I can't figure out why. It's suppose to set the enemy who's been placed into an Array.
 var SLT: Array = new Array();
 var Homing: GameObject;
 var current: int = 0;
 var slShot: GameObject = Instantiate(Homing, transform.position, Quaternion.identity);
 slShot.transform.GetComponent("Projectile").Target = SLT[current].transform;
 slShot.rigidbody.AddForce(transform.forward * 10, ForceMode.Impulse);
Here's the Projectile's script:
 static var Target: Transform;
 
 function Update(){
 
 
 transform.LookAt(Target);
 transform.position = Vector3.Lerp(transform.position, Target.position, Time.deltaTime * 10);
 Destroy(gameObject, 3);
 }
               Comment
              
 
               
              Answer by Oninji · Dec 13, 2011 at 06:17 PM
Since your Target is a Static var, you do not need to set it in the specific script. You can just do
 Target = SLT[current].transform
Tell if it's of any help.
The bullets spawn, but they don't move. The rigidbody's force isn't being applied and the target isn't being set.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                