Mini-Games-Game/Assets/Scripts/Hamor.cs
Santi cac9e28067 Documentation: Added Whack-A-Mole PDF
Unity: Created Whak-A-Mole Prototype Scene, Script and Added Score Functinality
2024-05-02 12:57:13 +01:00

57 lines
1.2 KiB
C#

using System.Collections;
using System.Collections.Generic;
using System.Dynamic;
using TMPro;
using UnityEngine;
public class Hamor : MonoBehaviour
{
public Animator hamorAnimator;
public GameObject bonkParticles;
public GameObject contact;
public bool particles = false;
public TextMeshProUGUI scoreText;
public int score = 0;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if(Input.GetMouseButtonDown(0))
{
hamorAnimator.SetTrigger("Bonk");
}
}
IEnumerator BonkTimer()
{
yield return new WaitForSeconds(1);
particles = false;
}
private void OnTriggerEnter(Collider other) {
if(particles == false)
{
if(other.tag != "Player")
{
var bitch = Instantiate(bonkParticles, contact.transform.position, Quaternion.identity);
Destroy(bitch, 1);
particles = true;
StartCoroutine(BonkTimer());
}
}
if(other.gameObject.tag == "Mole")
{
score += 1;
scoreText.text = "Score: " + score.ToString();
}
}
}