1
Fork 0
mirror of https://github.com/Steffo99/keep-everything-alive.git synced 2024-11-23 09:54:19 +00:00
keep-everything-alive/Assets/Scripts/Microgame_Nothing/Destructible.cs

38 lines
No EOL
991 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(SpriteRenderer))]
[RequireComponent(typeof(AudioSource))]
public class Destructible : MonoBehaviour {
public Sprite normalSprite;
public Sprite destroyedSprite;
private Animator animator;
private SpriteRenderer spriteRenderer;
private AudioSource audioSource;
private bool destroyed;
public bool Destroyed {
get {
return destroyed;
}
set {
destroyed = value;
spriteRenderer.sprite = (value ? destroyedSprite : normalSprite);
if(animator != null) {
animator.enabled = !value;
}
if(value) {
audioSource.Play();
}
}
}
private void Awake() {
animator = GetComponent<Animator>();
spriteRenderer = GetComponent<SpriteRenderer>();
audioSource = GetComponent<AudioSource>();
}
}