94 lines
3.1 KiB
C#
94 lines
3.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Unity.VisualScripting;
|
|
using UnityEngine;
|
|
|
|
public class Moles : MonoBehaviour
|
|
{
|
|
public GameObject hole1, hole2, hole3, hole4, hole5, hole6, hole7, hole8, hole9;
|
|
public GameObject mole;
|
|
private float defaultSpeed = 10f;
|
|
public float lifeTime = 7.5f;
|
|
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:
|
|
var bitch = Instantiate(mole, hole1.transform.position, Quaternion.identity);
|
|
Destroy(bitch, lifeTime);
|
|
break;
|
|
case 2:
|
|
var bitch2 = Instantiate(mole, hole2.transform.position, Quaternion.identity);
|
|
Destroy(bitch2, lifeTime);
|
|
break;
|
|
case 3:
|
|
var bitch3 = Instantiate(mole, hole3.transform.position, Quaternion.identity);
|
|
Destroy(bitch3, lifeTime);
|
|
break;
|
|
case 4:
|
|
var bitch4 = Instantiate(mole, hole4.transform.position, Quaternion.identity);
|
|
Destroy(bitch4, lifeTime);
|
|
break;
|
|
case 5:
|
|
var bitch5 = Instantiate(mole, hole5.transform.position, Quaternion.identity);
|
|
Destroy(bitch5, lifeTime);
|
|
break;
|
|
case 6:
|
|
var bitch6 = Instantiate(mole, hole6.transform.position, Quaternion.identity);
|
|
Destroy(bitch6, lifeTime);
|
|
break;;
|
|
case 7:
|
|
var bitch7 = Instantiate(mole, hole7.transform.position, Quaternion.identity);
|
|
Destroy(bitch7, lifeTime);
|
|
break;
|
|
case 8:
|
|
var bitch8 = Instantiate(mole, hole8.transform.position, Quaternion.identity);
|
|
Destroy(bitch8, lifeTime);
|
|
break;
|
|
case 9:
|
|
var bitch9 = Instantiate(mole, hole9.transform.position, Quaternion.identity);
|
|
Destroy(bitch9, lifeTime);
|
|
break;
|
|
}
|
|
}
|
|
|
|
IEnumerator MoleTimer()
|
|
{
|
|
yield return new WaitForSeconds(defaultSpeed);
|
|
moleCanAppear = true;
|
|
}
|
|
}
|