using System.Collections; using System.Collections.Generic; using UnityEngine; public class BreakOre : MonoBehaviour { public string name; public Sprite[] sprites; private int oldSprite; private int newSprite; private List availableSprites = new List(); public ParticleSystem breakParticleSystem; public bool timeToBreak = false; public int isBroken; void Start() { oldSprite = 0; for (int i = 0; i < 2; i++) { availableSprites.Add(i); } if (OnMapAppearanceMethod.IsNewGame()) { isBroken = 0; // TODO Like in NPC Type script } else { isBroken = PlayerPrefs.GetInt(name + "-S"); } if (isBroken == 1) { gameObject.SetActive(false); } } IEnumerator Timer() { if (timeToBreak == true) { isBroken = 1; gameObject.SetActive(false); PlayerPrefs.SetInt(name, isBroken); Debug.Log("drop item"); // drop item gameObject.GetComponent().DropItem(); } yield return new WaitForSeconds(1); var em = breakParticleSystem.emission; em.enabled = false; } private void OnTriggerEnter2D(Collider2D collision) { if (collision.tag == "PickaxeHitbox") { var em = breakParticleSystem.emission; em.enabled = true; breakParticleSystem.Play(); if (oldSprite == 0) { newSprite = availableSprites[1]; oldSprite = 1; GetComponent().sprite = sprites[newSprite]; } else if (oldSprite == 1) { timeToBreak = true; StartCoroutine(Timer()); } GetComponent().sprite = sprites[newSprite]; StartCoroutine(Timer()); } } public void SaveCheckpoint() { PlayerPrefs.SetInt(name + "-S", isBroken); } }