Hi everybody
I’m making a script to use for my cart system. This system exists out of a cart which moves on the same route thanks due a loop animation, and a trigger object attached to the car with this script:
static var destroyedobject : GameObject;
function Update(){
if(ClassSelectionScript.classselected == true && CartScript.seated == false){
destroyedobject = GameObject.FindWithTag("Player");
}
}
function OnTriggerEnter(otherObj: Collider){
if (otherObj.tag == "Player"){
Destroy(destroyedobject);
CartScript.seated = true;
}
}
The cart also has a script attached:
static var stopcommand : boolean = false;
static var seated : boolean = false;
function Update () {
if(seated == true){
stopcommand = true;
}
}
And the place the player leaves the cart, just a ordinary mesh with a trigger object, which has this script attached:
var instantiatedobject : GameObject;
function Update (){
if (CartTrigger.destroyedobject != null){
instantiatedobject = CartTrigger.destroyedobject;
}
}
function OnTriggerEnter(otherObj: Collider){
if (CartScript.stopcommand == true){
var instance : GameObject = Instantiate(instantiatedobject, transform.position+Vector3(1,0,0), transform.rotation);
CartScript.stopcommand = false;
CartScript.seated = false;
CartTrigger.destroyedbject = null;
}
}
What I’m trying to do is making the cart store the player and all the scripts and variables attached to it after destroying him, and instantiating him at the stopping point. The script destroys the player, but it doesn’t instantiate him when the cart enters the trigger. Does the script maybe reset the variable when the player is killed?
Please help me solve this problem!