mirror of
https://github.com/Steffo99/keep-everything-alive.git
synced 2024-11-23 18:04:18 +00:00
48 lines
1.3 KiB
C#
48 lines
1.3 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
[RequireComponent(typeof(AudioSource))]
|
|
[RequireComponent(typeof(SpriteRenderer))]
|
|
public class EatIfOver : MonoBehaviour
|
|
{
|
|
public Sprite defaultSprite;
|
|
public Sprite mouthOpenSprite;
|
|
public Sprite satisfiedSprite;
|
|
|
|
private AudioSource audioSource;
|
|
private SpriteRenderer spriteRenderer;
|
|
private MicrogameController microgameController;
|
|
private bool eaten;
|
|
|
|
void Awake() {
|
|
microgameController = GameObject.FindGameObjectWithTag("MicrogameController").GetComponent<MicrogameController>();
|
|
audioSource = GetComponent<AudioSource>();
|
|
spriteRenderer = GetComponent<SpriteRenderer>();
|
|
}
|
|
|
|
void Start() {
|
|
eaten = false;
|
|
}
|
|
|
|
void OnTriggerStay2D(Collider2D other) {
|
|
if(other.tag == "Enemy") {
|
|
if(Input.GetMouseButton(0)) {
|
|
spriteRenderer.sprite = mouthOpenSprite;
|
|
}
|
|
else {
|
|
spriteRenderer.sprite = satisfiedSprite;
|
|
audioSource.Play();
|
|
eaten = true;
|
|
microgameController.victory = true;
|
|
Destroy(other.gameObject);
|
|
}
|
|
}
|
|
}
|
|
|
|
void OnTriggerExit2D(Collider2D other) {
|
|
if(!eaten) {
|
|
spriteRenderer.sprite = defaultSprite;
|
|
}
|
|
}
|
|
}
|