Hello guys, I am making a 2D game, where the main objective is to avoid certain traps that the “environment” has for you. Similar to all the ‘I Wanna be the …’ series. All the traps consists on different events (OnTriggerEnter2d or OnCollisionEnter2D) that my character activates as he walks in the scenario.
The issue is that in many of them, its position is changed. For example in this code:
void OnTriggerEnter2D(Collider2D col){
string name = col.name;
if ( name == "Trap1Detector") {
GameObject trap = GameObject.Find("Trap1") as GameObject;
float xAct = trap.transform.position.x;
float yAct = trap.transform.position.y;
trap.transform.position = new Vector2(xAct,yAct +3);
col.isTrigger = false;
}
}
And if my player trigger one of those events, and then dies, when he respawn the scenario remains changed, with all the traps already “activated”.
Is there a way of “re-setting” or returning the scenario to its dfault state (the one that has one the game starts) when my player dies?
I don’t want to do move every single trap to its default state by hand…
The respawning script contains the following code:
using UnityEngine;
using System.Collections;
public class Respawn : MonoBehaviour {
public GameObject personaje;
public Transform ptoDeSpawn;
void OnTriggerEnter2D(Collider2D coll){
print ("holi");
Destroy (coll.gameObject);
if (personaje) {
GameObject p = Instantiate (personaje, ptoDeSpawn.position, Quaternion.identity) as GameObject;
CamaraController cam = Camera.main.gameObject.GetComponent<CamaraController> ();
cam.objetivo = p.transform;
}
}
}
THANKS!