2024-05-02 12:57:13 +01:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
2024-06-07 14:37:52 +01:00
|
|
|
using JetBrains.Annotations;
|
2024-05-02 12:57:13 +01:00
|
|
|
using Unity.VisualScripting;
|
|
|
|
using UnityEngine;
|
|
|
|
|
2024-06-07 14:37:52 +01:00
|
|
|
//TODO Moles need to change textures when hit to show they have been hit - need textures for this
|
|
|
|
//* As the time goes on, moles appear and disappear faster
|
2024-05-04 01:01:27 +01:00
|
|
|
|
2024-05-02 12:57:13 +01:00
|
|
|
public class Moles : MonoBehaviour
|
|
|
|
{
|
|
|
|
public GameObject hole1, hole2, hole3, hole4, hole5, hole6, hole7, hole8, hole9;
|
|
|
|
public GameObject mole;
|
|
|
|
private float defaultSpeed = 10f;
|
2024-06-07 14:37:52 +01:00
|
|
|
public float lifeTime = 5f;
|
2024-05-02 12:57:13 +01:00
|
|
|
public bool moleCanAppear = false;
|
|
|
|
public int randomHole, randomHole2, randomHole3;
|
|
|
|
// Start is called before the first frame update
|
|
|
|
void Start()
|
|
|
|
{
|
|
|
|
moleCanAppear = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
void Update()
|
|
|
|
{
|
|
|
|
if(moleCanAppear)
|
|
|
|
{
|
|
|
|
randomHole = Random.Range(1, 9);
|
|
|
|
randomHole2 = Random.Range(1, 9);
|
|
|
|
while(randomHole2 == randomHole)
|
|
|
|
{
|
|
|
|
randomHole2 = Random.Range(1, 9);
|
|
|
|
}
|
|
|
|
randomHole3 = Random.Range(1, 9);
|
|
|
|
while(randomHole3 == randomHole || randomHole3 == randomHole2)
|
|
|
|
{
|
|
|
|
randomHole3 = Random.Range(1, 9);
|
|
|
|
}
|
|
|
|
moleCanAppear = false;
|
|
|
|
holeSelection(randomHole);
|
|
|
|
holeSelection(randomHole2);
|
|
|
|
holeSelection(randomHole3);
|
|
|
|
StartCoroutine(MoleTimer());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void holeSelection(int randomHole)
|
|
|
|
{
|
|
|
|
// Prevent the same hole from being selected twice
|
|
|
|
switch (randomHole)
|
|
|
|
{
|
|
|
|
case 1:
|
2024-06-07 14:37:52 +01:00
|
|
|
var boxLocation = Instantiate(mole, hole1.transform.position, Quaternion.identity);
|
|
|
|
|
|
|
|
Destroy(boxLocation, lifeTime);
|
2024-05-02 12:57:13 +01:00
|
|
|
break;
|
|
|
|
case 2:
|
2024-06-07 14:37:52 +01:00
|
|
|
var boxLocation2 = Instantiate(mole, hole2.transform.position, Quaternion.identity);
|
|
|
|
Destroy(boxLocation2, lifeTime);
|
2024-05-02 12:57:13 +01:00
|
|
|
break;
|
|
|
|
case 3:
|
2024-06-07 14:37:52 +01:00
|
|
|
var boxLocation3 = Instantiate(mole, hole3.transform.position, Quaternion.identity);
|
|
|
|
Destroy(boxLocation3, lifeTime);
|
2024-05-02 12:57:13 +01:00
|
|
|
break;
|
|
|
|
case 4:
|
2024-06-07 14:37:52 +01:00
|
|
|
var boxLocation4 = Instantiate(mole, hole4.transform.position, Quaternion.identity);
|
|
|
|
Destroy(boxLocation4, lifeTime);
|
2024-05-02 12:57:13 +01:00
|
|
|
break;
|
|
|
|
case 5:
|
2024-06-07 14:37:52 +01:00
|
|
|
var boxLocation5 = Instantiate(mole, hole5.transform.position, Quaternion.identity);
|
|
|
|
Destroy(boxLocation5, lifeTime);
|
2024-05-02 12:57:13 +01:00
|
|
|
break;
|
|
|
|
case 6:
|
2024-06-07 14:37:52 +01:00
|
|
|
var boxLocation6 = Instantiate(mole, hole6.transform.position, Quaternion.identity);
|
|
|
|
Destroy(boxLocation6, lifeTime);
|
2024-05-02 12:57:13 +01:00
|
|
|
break;;
|
|
|
|
case 7:
|
2024-06-07 14:37:52 +01:00
|
|
|
var boxLocation7 = Instantiate(mole, hole7.transform.position, Quaternion.identity);
|
|
|
|
Destroy(boxLocation7, lifeTime);
|
2024-05-02 12:57:13 +01:00
|
|
|
break;
|
|
|
|
case 8:
|
2024-06-07 14:37:52 +01:00
|
|
|
var boxLocation8 = Instantiate(mole, hole8.transform.position, Quaternion.identity);
|
|
|
|
Destroy(boxLocation8, lifeTime);
|
2024-05-02 12:57:13 +01:00
|
|
|
break;
|
|
|
|
case 9:
|
2024-06-07 14:37:52 +01:00
|
|
|
var boxLocation9 = Instantiate(mole, hole9.transform.position, Quaternion.identity);
|
|
|
|
Destroy(boxLocation9, lifeTime);
|
2024-05-02 12:57:13 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
IEnumerator MoleTimer()
|
|
|
|
{
|
|
|
|
yield return new WaitForSeconds(defaultSpeed);
|
|
|
|
moleCanAppear = true;
|
|
|
|
}
|
|
|
|
}
|