using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PickaxeHolder : MonoBehaviour
{
[SerializeField] private Pickaxe[] pickaxeArray;
private string lastPickaxe;
[SerializeField] private Sprite stonePickaxeSprite;
public string PickaxeName { get; private set; }
public int PickaxeCost { get; private set; }
private Sprite PickaxeSprite;
private SpriteRenderer pickaxeSpriteRenderer;
private void Start()
{
ClickButton.OnClickButtonDownEvent += RotatePickaxeOnClick;
ClickButton.OnClickButtonUpEvent += RotatePickaxeToAveragePosition;
pickaxeSpriteRenderer = GetComponent<SpriteRenderer>();
DefinePickaxeParamsOnLoad();
RotatePickaxeToAveragePosition();
}
private void Update()
{
pickaxeSpriteRenderer.sprite = PickaxeSprite;
}
private void DefinePickaxeParamsOnLoad()
{
lastPickaxe = PlayerPrefs.GetString("LastPickaxe");
switch (lastPickaxe)
{
case "IronPickaxe":
SetPickaxeParams(pickaxeArray[0].PickaxeName, pickaxeArray[0].PickaxeCost, pickaxeArray[0].PickaxeSprite);
break;
case "GoldPickaxe":
SetPickaxeParams(pickaxeArray[1].PickaxeName, pickaxeArray[1].PickaxeCost, pickaxeArray[1].PickaxeSprite);
break;
case "DiamondPickaxe":
SetPickaxeParams(pickaxeArray[2].PickaxeName, pickaxeArray[2].PickaxeCost, pickaxeArray[2].PickaxeSprite);
break;
case "EmeraldPickaxe":
SetPickaxeParams(pickaxeArray[3].PickaxeName, pickaxeArray[3].PickaxeCost, pickaxeArray[3].PickaxeSprite);
break;
default:
SetPickaxeParams("StonePickaxe", 0, stonePickaxeSprite);
break;
}
}
private void SetPickaxeParams(string _pickaxeName, int _pickaxeCost, Sprite _pickaxeSprite)
{
PickaxeName = _pickaxeName;
PickaxeCost = _pickaxeCost;
PickaxeSprite = _pickaxeSprite;
lastPickaxe = _pickaxeName;
PlayerPrefs.SetString("LastPickaxe", lastPickaxe);
}
private void RotatePickaxeOnClick()
{
transform.localRotation = Quaternion.Euler(0f, 0f, -90f);
}
private void RotatePickaxeToAveragePosition()
{
transform.localRotation = Quaternion.Euler(0f, 0f, 0f);
}
}