Files
Gnome-s-Bounty/Assets/Scripts/Player.cs
T
2023-06-28 13:38:48 +03:00

65 lines
1.4 KiB
C#

using UnityEngine;
public class Player : Character
{
[SerializeField]
private Transform _hammerSpawnPoint;
[SerializeField]
private GameObject _hammerPrefab;
private int _hammerSpeed=10;
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()
{
if (Input.GetKeyDown(KeyCode.Space))
{
var hammer = Instantiate(_hammerPrefab, _hammerSpawnPoint.position, _hammerSpawnPoint.rotation);
hammer.GetComponent<Rigidbody2D>().velocity = new Vector2(gameObject.transform.localScale.x * _hammerSpeed,0);
}
base.MoveTo(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
}
}