using UnityEngine; using System.Collections; using UnityEngine.Rendering; using UnityEngine.Rendering.Universal; using UnityEngine.SceneManagement; public class Pukvbrane : MonoBehaviour { AudioSource audioSource; public HuDcko hudcko; public GameObject puk; public int maxcubes = 3; 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 if (Random.Range(0, 3) == 0) { y = 880; } GameObject iks = Instantiate(puk.gameObject, new Vector3(x, y, z), Quaternion.identity); iks.SetActive(true); } void Start() { audioSource = GetComponent(); } public void StartCubes(){ 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(); } if (collectedcubes == maxcubes){ hudcko.won = true; SceneManager.LoadScene("End"); } } } public void Update() { hudcko.collectedcubes = collectedcubes; hudcko.collectedcubes_max = maxcubes; } }