1
Fork 0
mirror of https://github.com/Steffo99/keep-everything-alive.git synced 2024-11-30 21:14:18 +00:00
keep-everything-alive/Assets/Scripts/Microgame_Nothing/Destructible.cs

38 lines
991 B
C#
Raw Normal View History

2020-04-20 17:34:49 +00:00
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>();
}
}