54 lines
1.5 KiB
C#
54 lines
1.5 KiB
C#
|
|
using System.Collections;
|
||
|
|
using System.Collections.Generic;
|
||
|
|
using UnityEngine;
|
||
|
|
|
||
|
|
public class DyingPlayerController : MonoBehaviour {
|
||
|
|
[SerializeField] AudioClip die;
|
||
|
|
[SerializeField] AudioClip boom;
|
||
|
|
[SerializeField] float deathTime = 1.5f; // seconds
|
||
|
|
[SerializeField] Color glowColor = Color.red; // seconds
|
||
|
|
[SerializeField] float glowFrequency = 10f; // per second
|
||
|
|
[SerializeField] bool glowing = true;
|
||
|
|
[SerializeField] GameObject explosion;
|
||
|
|
|
||
|
|
AudioSource audioSource;
|
||
|
|
SpriteRenderer sprite;
|
||
|
|
|
||
|
|
// Start is called before the first frame update
|
||
|
|
void Start() {
|
||
|
|
}
|
||
|
|
|
||
|
|
private void Awake() {
|
||
|
|
audioSource = GameObject.FindGameObjectWithTag("PegLegIoGame").GetComponent<AudioSource>();
|
||
|
|
sprite = GetComponent<SpriteRenderer>();
|
||
|
|
audioSource.PlayOneShot(die);
|
||
|
|
if (glowing) {
|
||
|
|
StartCoroutine(Glow());
|
||
|
|
}
|
||
|
|
StartCoroutine(Die());
|
||
|
|
}
|
||
|
|
|
||
|
|
private IEnumerator Glow() {
|
||
|
|
while (true) {
|
||
|
|
sprite.color = glowColor;
|
||
|
|
yield return new WaitForSeconds(1.0f / glowFrequency);
|
||
|
|
sprite.color = Color.white;
|
||
|
|
yield return new WaitForSeconds(1.0f / glowFrequency);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
private IEnumerator Die() {
|
||
|
|
yield return new WaitForSeconds(deathTime);
|
||
|
|
audioSource.PlayOneShot(boom);
|
||
|
|
GameObject e = Instantiate(explosion);
|
||
|
|
e.transform.position = transform.position;
|
||
|
|
Destroy(gameObject);
|
||
|
|
}
|
||
|
|
|
||
|
|
// Update is called once per frame
|
||
|
|
void Update()
|
||
|
|
{
|
||
|
|
|
||
|
|
}
|
||
|
|
}
|