2024-05-02 12:57:13 +01:00
|
|
|
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;
|
2024-06-07 14:37:52 +01:00
|
|
|
public Moles_IsHit moles;
|
|
|
|
//*Start is called before the first frame update
|
2024-05-02 12:57:13 +01:00
|
|
|
void Start()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2024-06-07 14:37:52 +01:00
|
|
|
//*Update is called once per frame
|
2024-05-02 12:57:13 +01:00
|
|
|
void Update()
|
|
|
|
{
|
|
|
|
if(Input.GetMouseButtonDown(0))
|
|
|
|
{
|
2024-06-07 14:37:52 +01:00
|
|
|
hamorAnimator.SetTrigger("Bonk"); //*Play the bonk animation
|
2024-05-02 12:57:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
IEnumerator BonkTimer()
|
|
|
|
{
|
|
|
|
yield return new WaitForSeconds(1);
|
|
|
|
particles = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnTriggerEnter(Collider other) {
|
|
|
|
if(particles == false)
|
|
|
|
{
|
|
|
|
if(other.tag != "Player")
|
|
|
|
{
|
2024-06-07 14:37:52 +01:00
|
|
|
//*Play the bonk particles
|
|
|
|
var parLocation = Instantiate(bonkParticles, contact.transform.position, Quaternion.identity);
|
|
|
|
Destroy(parLocation, 1);
|
2024-05-02 12:57:13 +01:00
|
|
|
particles = true;
|
|
|
|
StartCoroutine(BonkTimer());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(other.gameObject.tag == "Mole")
|
|
|
|
{
|
2024-06-07 14:37:52 +01:00
|
|
|
//*Get the Moles_IsHit script from the mole
|
|
|
|
moles = other.gameObject.GetComponent<Moles_IsHit>();
|
|
|
|
|
|
|
|
//*If the mole has not been hit, increase the score and change bool
|
|
|
|
if(moles.IsHit == false)
|
|
|
|
{
|
|
|
|
score += 1;
|
|
|
|
scoreText.text = "Score: " + score.ToString();
|
|
|
|
moles.IsHit = true;
|
|
|
|
}
|
2024-05-02 12:57:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|