1
Fork 0
mirror of https://github.com/Steffo99/keep-everything-alive.git synced 2024-11-25 18:54:19 +00:00
keep-everything-alive/Assets/Scripts/Microgame_IT/EatIfOver.cs

49 lines
1.3 KiB
C#
Raw Normal View History

2020-04-20 19:31:30 +00:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(AudioSource))]
2020-04-20 20:45:36 +00:00
[RequireComponent(typeof(SpriteRenderer))]
2020-04-20 19:31:30 +00:00
public class EatIfOver : MonoBehaviour
{
2020-04-20 20:45:36 +00:00
public Sprite defaultSprite;
public Sprite mouthOpenSprite;
public Sprite satisfiedSprite;
2020-04-20 19:31:30 +00:00
private AudioSource audioSource;
2020-04-20 20:45:36 +00:00
private SpriteRenderer spriteRenderer;
private MicrogameController microgameController;
private bool eaten;
2020-04-20 19:31:30 +00:00
void Awake() {
2020-04-20 20:45:36 +00:00
microgameController = GameObject.FindGameObjectWithTag("MicrogameController").GetComponent<MicrogameController>();
2020-04-20 19:31:30 +00:00
audioSource = GetComponent<AudioSource>();
2020-04-20 20:45:36 +00:00
spriteRenderer = GetComponent<SpriteRenderer>();
}
void Start() {
eaten = false;
2020-04-20 19:31:30 +00:00
}
void OnTriggerStay2D(Collider2D other) {
2020-04-20 20:45:36 +00:00
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;
2020-04-20 19:31:30 +00:00
}
}
}