2022-04-25 21:41:47 +02:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
|
|
public class breakable : MonoBehaviour
|
|
|
|
{
|
2022-06-15 19:54:44 +02:00
|
|
|
public string name;
|
2022-04-25 21:41:47 +02:00
|
|
|
public Sprite[] sprites;
|
|
|
|
private int oldSprite;
|
|
|
|
private int newSprite;
|
|
|
|
private List<int> availableSprites = new List<int>();
|
2022-06-02 09:49:51 +02:00
|
|
|
public ParticleSystem collisionParticleSystem;
|
|
|
|
public bool timeToBreak = false;
|
2022-06-15 19:54:44 +02:00
|
|
|
private int isBroken = 0;
|
2022-06-02 09:49:51 +02:00
|
|
|
|
2022-04-25 21:41:47 +02:00
|
|
|
|
|
|
|
|
|
|
|
void Start()
|
|
|
|
{
|
2022-06-15 19:54:44 +02:00
|
|
|
|
2022-04-25 21:41:47 +02:00
|
|
|
for(int i=0; i<3; i++)
|
|
|
|
{
|
|
|
|
availableSprites.Add(i);
|
|
|
|
}
|
2022-06-15 19:54:44 +02:00
|
|
|
|
2022-12-06 01:20:01 +01:00
|
|
|
if (OnMapAppearanceMethod.IsNewGame())
|
2022-06-15 19:54:44 +02:00
|
|
|
{
|
2022-10-02 18:45:58 +02:00
|
|
|
isBroken = 0;
|
2022-06-15 19:54:44 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-10-02 18:45:58 +02:00
|
|
|
isBroken = PlayerPrefs.GetInt(name + "-S");
|
2022-06-15 19:54:44 +02:00
|
|
|
}
|
2022-10-02 18:45:58 +02:00
|
|
|
|
2022-06-15 19:54:44 +02:00
|
|
|
if(isBroken == 0)
|
|
|
|
{
|
|
|
|
oldSprite = 0;
|
|
|
|
GetComponent<SpriteRenderer>().sprite = sprites[oldSprite];
|
|
|
|
}
|
|
|
|
else if (isBroken == 1)
|
|
|
|
{
|
|
|
|
oldSprite = 1;
|
|
|
|
GetComponent<SpriteRenderer>().sprite = sprites[oldSprite];
|
|
|
|
}
|
|
|
|
else if (isBroken == 2)
|
|
|
|
{
|
|
|
|
oldSprite = 2;
|
|
|
|
GetComponent<SpriteRenderer>().sprite = sprites[oldSprite];
|
|
|
|
}
|
|
|
|
else if(isBroken == 3)
|
2022-06-02 18:32:18 +02:00
|
|
|
{
|
2022-11-10 16:00:57 +01:00
|
|
|
PlayerPrefs.SetInt(name, isBroken);
|
|
|
|
|
2022-06-12 17:18:43 +02:00
|
|
|
gameObject.SetActive(false);
|
2022-06-02 18:32:18 +02:00
|
|
|
}
|
2022-06-02 09:49:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
IEnumerator Timer()
|
|
|
|
{
|
|
|
|
if (timeToBreak == true){
|
2022-11-10 16:00:57 +01:00
|
|
|
//isBroken = 3;
|
2022-06-12 17:18:43 +02:00
|
|
|
gameObject.SetActive(false);
|
2022-06-02 09:49:51 +02:00
|
|
|
}
|
|
|
|
yield return new WaitForSeconds(1);
|
|
|
|
var em = collisionParticleSystem.emission;
|
|
|
|
em.enabled = false;
|
2022-04-25 21:41:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void OnTriggerEnter2D(Collider2D collision)
|
|
|
|
{
|
2022-07-03 22:15:56 +02:00
|
|
|
if (collision.tag == "PickaxeHitbox")
|
2022-04-25 21:41:47 +02:00
|
|
|
{
|
2022-06-12 11:28:14 +02:00
|
|
|
var em = collisionParticleSystem.emission;
|
|
|
|
em.enabled = true;
|
2022-06-02 09:49:51 +02:00
|
|
|
collisionParticleSystem.Play();
|
|
|
|
if (oldSprite == 0)
|
|
|
|
{
|
|
|
|
newSprite = availableSprites[1];
|
|
|
|
oldSprite = 1;
|
|
|
|
GetComponent<SpriteRenderer>().sprite = sprites[newSprite];
|
2022-06-15 19:54:44 +02:00
|
|
|
isBroken = 1;
|
2022-06-02 09:49:51 +02:00
|
|
|
}
|
|
|
|
else if (oldSprite == 1)
|
|
|
|
{
|
|
|
|
newSprite = availableSprites[2];
|
|
|
|
oldSprite = 2;
|
2022-04-25 21:41:47 +02:00
|
|
|
GetComponent<SpriteRenderer>().sprite = sprites[newSprite];
|
2022-06-15 19:54:44 +02:00
|
|
|
isBroken = 2;
|
2022-06-02 09:49:51 +02:00
|
|
|
}
|
|
|
|
else if (oldSprite == 2)
|
|
|
|
{
|
|
|
|
timeToBreak = true;
|
2022-11-10 16:00:57 +01:00
|
|
|
isBroken = 3;
|
|
|
|
//StartCoroutine(Timer());
|
2022-06-02 09:49:51 +02:00
|
|
|
}
|
|
|
|
GetComponent<SpriteRenderer>().sprite = sprites[newSprite];
|
|
|
|
StartCoroutine(Timer());
|
2022-04-25 21:41:47 +02:00
|
|
|
}
|
|
|
|
|
2022-06-02 09:49:51 +02:00
|
|
|
}
|
2022-06-15 19:54:44 +02:00
|
|
|
|
|
|
|
|
|
|
|
public void SaveCheckpoint()
|
|
|
|
{
|
2022-10-02 18:45:58 +02:00
|
|
|
PlayerPrefs.SetInt(name + "-S", isBroken);
|
2022-06-15 19:54:44 +02:00
|
|
|
}
|
2022-04-25 21:41:47 +02:00
|
|
|
}
|