61 lines
1.4 KiB
C#
61 lines
1.4 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class BreakOre : MonoBehaviour
|
|
{
|
|
public Sprite[] sprites;
|
|
private int oldSprite;
|
|
private int newSprite;
|
|
private List<int> availableSprites = new List<int>();
|
|
public ParticleSystem breakParticleSystem;
|
|
public bool timeToBreak = false;
|
|
|
|
|
|
|
|
void Start()
|
|
{
|
|
oldSprite = 0;
|
|
for (int i = 0; i < 2; i++)
|
|
{
|
|
availableSprites.Add(i);
|
|
}
|
|
|
|
}
|
|
|
|
IEnumerator Timer()
|
|
{
|
|
if (timeToBreak == true)
|
|
{
|
|
gameObject.SetActive(false);
|
|
}
|
|
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());
|
|
}
|
|
|
|
}
|
|
}
|