2022-06-25 15:42:49 +02:00
|
|
|
using UnityEngine;
|
|
|
|
using System.Collections;
|
|
|
|
using UnityEngine.Rendering;
|
|
|
|
using UnityEngine.Rendering.Universal;
|
2022-06-27 11:54:53 +02:00
|
|
|
using UnityEngine.SceneManagement;
|
2022-06-25 15:42:49 +02:00
|
|
|
|
|
|
|
public class Pukvbrane : MonoBehaviour
|
|
|
|
{
|
|
|
|
AudioSource audioSource;
|
|
|
|
public HuDcko hudcko;
|
|
|
|
public GameObject puk;
|
2022-06-27 11:54:53 +02:00
|
|
|
public int maxcubes = 3;
|
2022-06-25 15:42:49 +02:00
|
|
|
public int collectedcubes = 0;
|
|
|
|
|
|
|
|
|
|
|
|
public void PlaceObj(){
|
|
|
|
int x = Random.Range(-821, 1000);
|
|
|
|
int z = Random.Range(-950, 950);
|
|
|
|
int y = -55;
|
|
|
|
//pick y from either -75 and 845
|
2022-06-27 11:54:53 +02:00
|
|
|
if (Random.Range(0, 3) == 0)
|
2022-06-25 15:42:49 +02:00
|
|
|
{
|
|
|
|
y = 880;
|
|
|
|
}
|
|
|
|
GameObject iks = Instantiate(puk.gameObject, new Vector3(x, y, z), Quaternion.identity);
|
|
|
|
iks.SetActive(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Start()
|
|
|
|
{
|
|
|
|
audioSource = GetComponent<AudioSource>();
|
2022-06-27 11:54:53 +02:00
|
|
|
}
|
|
|
|
public void StartCubes(){
|
2022-06-25 15:42:49 +02:00
|
|
|
PlaceObj();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnCollisionEnter(Collision collision)
|
|
|
|
{
|
|
|
|
if (collision.gameObject.tag == "puk")
|
|
|
|
{
|
|
|
|
audioSource.Play();
|
|
|
|
//generate two random numbers between -50 and 50
|
|
|
|
Destroy(collision.gameObject);
|
|
|
|
if (collectedcubes < maxcubes)
|
|
|
|
{
|
|
|
|
collectedcubes++;
|
|
|
|
PlaceObj();
|
|
|
|
}
|
2022-06-27 11:54:53 +02:00
|
|
|
if (collectedcubes == maxcubes){
|
2022-06-25 15:42:49 +02:00
|
|
|
hudcko.won = true;
|
2022-06-27 11:54:53 +02:00
|
|
|
SceneManager.LoadScene("End");
|
2022-06-25 15:42:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2022-06-27 11:54:53 +02:00
|
|
|
}
|
|
|
|
public void Update() {
|
2022-06-25 15:42:49 +02:00
|
|
|
hudcko.collectedcubes = collectedcubes;
|
|
|
|
hudcko.collectedcubes_max = maxcubes;
|
|
|
|
}
|
|
|
|
}
|