mirror of
https://github.com/Steffo99/keep-everything-alive.git
synced 2024-11-23 18:04:18 +00:00
38 lines
991 B
C#
38 lines
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>();
|
||
|
}
|
||
|
}
|