using UnityEngine;
using System.Collections;
[RequireComponent(typeof(PlayerSave))]
public class Ykill : MonoBehaviour {
public float yDeath = -100f;
private PlayerSave playerSave;
// Use this for initialization
void Start () {
playerSave = transform.GetComponent<PlayerSave>();
}
// Update is called once per frame
void Update () {
if (this.transform.position.y < yDeath)
playerSave.goToLastSavePoint();
}
}
using UnityEngine;
using System.Collections;
public class PlayerSave : MonoBehaviour {
private TriggerSave lastTriggerSave = null;
public void setTriggerSave(TriggerSave ts)
{
lastTriggerSave = ts;
}
public void goToLastSavePoint()
{
if (lastTriggerSave == null)
{
Application.LoadLevel(Application.loadedLevel);
}
else
{
this.transform.position = lastTriggerSave.playerPosOnTrigger;
}
}
}
using UnityEngine;
using System.Collections;
public class TriggerSave : MonoBehaviour {
public Vector3 playerPosOnTrigger;
void OnTriggerEnter(Collider col)
{
if (col.gameObject.tag == "Player")
{
PlayerSave ps = col.transform.GetComponent<PlayerSave>();
ps.setTriggerSave(this);
playerPosOnTrigger = col.transform.position;
}
}
}