Cours Unity contact(at)guillaumelevieux.com :: « Home


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();
	}
}

Y Kill


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;
        }
    }
}


Player Save


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;
        }
    }
}


Trigger Save




<< précédent  0  1  2  3  4  5  6  7  8  9  10  suivant >>