Need to add a reference to script once added with code?
i have two teleport scripts. both have differnt references and tags so should work, but Unity treats them as the same code. so when i use the second teleport area with that script, it takes me back to the exit of the first teleport. So i used a code that when triggered the script will be destroyed. this allows the second teleport to work. However, when i add the script back for the first teleport it is missing the target refence that allows teleport one to travel from a to b. so i need a way so that when i add the sciprt back it will add the reference with it.
here is my code to destroy and then re-add the script var rippletarget : Transform; //need to add this back in when the script is re-added function OnTriggerEnter (col : Collider) {
if (col.gameObject.tag == "disable") {
Destroy(GetComponent(Teleport));
}
else if (col.gameObject.tag == "enable") {
//UnityEngineInternal.APIUpdaterRuntimeServices.AddComponent(gameObject, "Assets/Scripts/MyGame/Teleport.js(7,17)", "Teleport");
gameObject.AddComponent.<Teleport>();
Destroy(GetComponent(TeleportBase));
}
}
Here is my code that teleport 1 uses function Update () {
}
function OnTriggerEnter (col : Collider) {
if (col.gameObject.tag == "ripple") {
this.transform.position = rippletarget.position;
}
}
Here is the code that teleport 2 uses var ripple2target : Transform;
function Update () {
}
function OnTriggerEnter (col : Collider) {
if (col.gameObject.tag == "ripple2") {
this.transform.position = ripple2target.position;
}
}
You have a typo. gameObject.AddComponent.<Teleport>();
should be gameObject.AddComponent<Teleport>();
$$anonymous$$eh. I believe that's the correct js syntax.
I'd be more interested to fix your original problem and get rid of removing scrpits. It is definitely possible to have 2 teleport sources taking you to the world position of 2 different targets respectively.