51 lines
972 B
C#
51 lines
972 B
C#
using UnityEngine;
|
|
|
|
public class Player : Character
|
|
{
|
|
private int _totalCoins = 0;
|
|
private bool _hasKey = false;
|
|
public static Player Instance { get; private set; }
|
|
|
|
private void Awake()
|
|
{
|
|
|
|
if (Instance != null)
|
|
{
|
|
Destroy(gameObject);
|
|
Debug.Log("There's more than one player instance");
|
|
return;
|
|
}
|
|
PlayerPrefs.SetString("lastExitName", string.Empty);
|
|
Instance = this;
|
|
DontDestroyOnLoad(gameObject);
|
|
}
|
|
|
|
|
|
public void AddCoin()
|
|
{
|
|
_totalCoins++;
|
|
print($"player have {_totalCoins} coins");
|
|
}
|
|
|
|
public void SetKey()
|
|
{
|
|
print($"player have key");
|
|
_hasKey =true;
|
|
}
|
|
|
|
public void RemoveKey()
|
|
{
|
|
_hasKey = false;
|
|
}
|
|
|
|
public bool IsHasKey()
|
|
{
|
|
return _hasKey;
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
base.MoveTo(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
|
|
}
|
|
}
|