2022-04-25 21:41:47 +02:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
|
|
public class breakable : MonoBehaviour
|
|
|
|
{
|
|
|
|
|
|
|
|
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-04-25 21:41:47 +02:00
|
|
|
|
|
|
|
|
|
|
|
void Start()
|
|
|
|
{
|
|
|
|
oldSprite = 0;
|
|
|
|
for(int i=0; i<3; i++)
|
|
|
|
{
|
|
|
|
availableSprites.Add(i);
|
|
|
|
}
|
2022-06-03 10:34:31 +02:00
|
|
|
int rock = PlayerPrefs.GetInt("rock");
|
2022-06-02 18:32:18 +02:00
|
|
|
if(rock == 0)
|
|
|
|
{
|
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-06-03 10:34:31 +02:00
|
|
|
PlayerPrefs.SetInt("rock", 0);
|
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-06-12 11:28:14 +02:00
|
|
|
if (collision.tag == "AttackHitbox")
|
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];
|
|
|
|
}
|
|
|
|
else if (oldSprite == 1)
|
|
|
|
{
|
|
|
|
newSprite = availableSprites[2];
|
|
|
|
oldSprite = 2;
|
2022-04-25 21:41:47 +02:00
|
|
|
GetComponent<SpriteRenderer>().sprite = sprites[newSprite];
|
2022-06-02 09:49:51 +02:00
|
|
|
}
|
|
|
|
else if (oldSprite == 2)
|
|
|
|
{
|
|
|
|
timeToBreak = true;
|
|
|
|
StartCoroutine(Timer());
|
|
|
|
}
|
|
|
|
GetComponent<SpriteRenderer>().sprite = sprites[newSprite];
|
|
|
|
StartCoroutine(Timer());
|
2022-04-25 21:41:47 +02:00
|
|
|
}
|
|
|
|
|
2022-06-02 09:49:51 +02:00
|
|
|
}
|
2022-04-25 21:41:47 +02:00
|
|
|
}
|