2022-06-15 14:59:30 +02:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
public class BreakOre : MonoBehaviour
|
|
|
|
{
|
2022-06-15 19:54:44 +02:00
|
|
|
|
|
|
|
public string name;
|
|
|
|
public string name2;
|
|
|
|
|
2022-06-15 14:59:30 +02:00
|
|
|
public Sprite[] sprites;
|
|
|
|
private int oldSprite;
|
|
|
|
private int newSprite;
|
|
|
|
private List<int> availableSprites = new List<int>();
|
|
|
|
public ParticleSystem breakParticleSystem;
|
|
|
|
public bool timeToBreak = false;
|
|
|
|
|
2022-06-15 19:54:44 +02:00
|
|
|
public int isBroken;
|
2022-06-15 14:59:30 +02:00
|
|
|
|
|
|
|
void Start()
|
|
|
|
{
|
|
|
|
oldSprite = 0;
|
|
|
|
for (int i = 0; i < 2; i++)
|
|
|
|
{
|
|
|
|
availableSprites.Add(i);
|
|
|
|
}
|
|
|
|
|
2022-06-15 19:54:44 +02:00
|
|
|
int continued = PlayerPrefs.GetInt("continued");
|
|
|
|
if (continued == 1)
|
|
|
|
{
|
|
|
|
isBroken = PlayerPrefs.GetInt(name2);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
isBroken = PlayerPrefs.GetInt(name);
|
|
|
|
}
|
|
|
|
if (isBroken == 1)
|
|
|
|
{
|
|
|
|
gameObject.SetActive(false);
|
|
|
|
}
|
|
|
|
|
2022-06-15 14:59:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
IEnumerator Timer()
|
|
|
|
{
|
|
|
|
if (timeToBreak == true)
|
|
|
|
{
|
2022-06-15 19:54:44 +02:00
|
|
|
isBroken = 1;
|
2022-06-15 14:59:30 +02:00
|
|
|
gameObject.SetActive(false);
|
2022-06-15 19:54:44 +02:00
|
|
|
PlayerPrefs.SetInt(name, isBroken);
|
2022-06-16 20:00:19 +02:00
|
|
|
Debug.Log("drop item");
|
2022-06-17 22:22:19 +02:00
|
|
|
// drop item
|
2022-06-16 20:00:19 +02:00
|
|
|
gameObject.GetComponent<GoldOre>().DropItem();
|
2022-06-15 14:59:30 +02:00
|
|
|
}
|
|
|
|
yield return new WaitForSeconds(1);
|
|
|
|
var em = breakParticleSystem.emission;
|
|
|
|
em.enabled = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnTriggerEnter2D(Collider2D collision)
|
|
|
|
{
|
|
|
|
if (collision.tag == "AttackHitbox")
|
|
|
|
{
|
|
|
|
var em = breakParticleSystem.emission;
|
|
|
|
em.enabled = true;
|
|
|
|
breakParticleSystem.Play();
|
|
|
|
if (oldSprite == 0)
|
|
|
|
{
|
|
|
|
newSprite = availableSprites[1];
|
|
|
|
oldSprite = 1;
|
|
|
|
GetComponent<SpriteRenderer>().sprite = sprites[newSprite];
|
|
|
|
}
|
|
|
|
else if (oldSprite == 1)
|
|
|
|
{
|
|
|
|
timeToBreak = true;
|
|
|
|
StartCoroutine(Timer());
|
|
|
|
}
|
|
|
|
GetComponent<SpriteRenderer>().sprite = sprites[newSprite];
|
|
|
|
StartCoroutine(Timer());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2022-06-15 19:54:44 +02:00
|
|
|
|
|
|
|
public void SaveCheckpoint()
|
|
|
|
{
|
|
|
|
PlayerPrefs.SetInt(name2, isBroken);
|
|
|
|
}
|
2022-06-15 14:59:30 +02:00
|
|
|
}
|