Hi, i just have a problem with my script, I have a problem when i Set The “Target” from another script. Maybe something like this:
from script A -Give a Target> Script B → Instantiate
from script C -Give a Target> Script B → Instantiate
Its work when the Script A just Instantiate the Script B, Then When Script C give an order to Script B, The Target from Script A is Changed to Target from Script C ,
How can i get the “Fix” target for my Script when i Instantiate the Script?
Sorry for my English , ![]()
I use GetComponent for scipt B, but still same, i use this script for Script A and C. But With The Different Target and Variable var Target : Transform; var Bullet : GameObject; var shoot : boolean = false; private var myGO : GameObject; function Update() { if(shoot) { ShootTheBullet(); } } function ShootTheBullet() { myGO = Instantiate(Bullet,transform.position,transform.rotation); var theScript = myGO.GetComponent(ScriptB); theScript.Target = Target; Shoot = false; }
– m4s4m0r1So this script looks fine. Is there still a problem, or is this the solution?
– robertbuthe problem is when i Instantiate the Bullet,,, when i "Shoot", The Bullet is go to the my target, but when my bullet still go to my target, then the AI "shoot" the bullet with the target is me,my Bullet Turn Around and Attack Me,, :) I Think how can i give the Fixed Target to My Bullet?
– m4s4m0r1Can you post the script for the bullet (ScriptB). Did you make the Target you set for the bullet static?
– robertbuyeah,,,Problem Solved I Set a Variable in scriptB as a Static var,, when i Change it to Public,, Its Work Thanks Very Much
– m4s4m0r1