i want to assign a gameobject to my just instantiated prefab.
the problem is. it needs to change depending on what lane the prefab spawned on. (each prefab needs to remember the object that spawned the prefab)
i have tried this:
public class Script_A : NetworkBehaviour {
public int number=5;
void Start(){
GameObject o = Instantiate(Prefab,Position,Rotation) as GameObject;
o.GetComponent<Script_B>().scriptA=this;
}
}
Now your Script_B Needs a global(public) Variable of Type Script_A (in my example it has the Name “scriptA” so Script_A can link itself (with “this”) to Script_B. Now after the new GameObject with Script_B attached has been spawned it can Access all global (public) Variables of Script_A:
public class Script_B : NetworkBehaviour{
public Script_A scriptA;
void Start(){
Debug.Log(scriptA.number);
}
}
Now your Script_B should print out the number 5 of Script_A