*
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class SavePoint : PlayerSensor {
|
||||
private GameAction _saveAction;
|
||||
private AudioSource _audio;
|
||||
private float lastSaveTime = -100;
|
||||
public float savePeriod = 5.0f;
|
||||
|
||||
void Start(){
|
||||
_saveAction = new GameAction();
|
||||
_saveAction.target = gameObject;
|
||||
_saveAction.text = "Save state";
|
||||
|
||||
_audio = GetComponent<AudioSource>();
|
||||
}
|
||||
|
||||
protected override void OnPlayerEnter (GameObject player)
|
||||
{
|
||||
base.OnPlayerEnter (player);
|
||||
ActionController.AddAction(_saveAction);
|
||||
}
|
||||
|
||||
protected override void OnPlayerExit (GameObject player)
|
||||
{
|
||||
base.OnPlayerExit (player);
|
||||
ActionController.RemoveAction(_saveAction);
|
||||
}
|
||||
|
||||
void OnAction(ActionArgs a){
|
||||
if(Time.time - lastSaveTime >= savePeriod){
|
||||
Debug.Log("Save");
|
||||
lastSaveTime = Time.time;
|
||||
if(_audio != null){
|
||||
_audio.Play();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user