using UnityEngine; using System.Collections; using UnityEngine.Rendering; using UnityEngine.Rendering.Universal; public class Pukvbrane : MonoBehaviour { AudioSource audioSource; public HuDcko hudcko; public GameObject puk; public int maxcubes = 20; 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, 2) == 0) { y = 880; } GameObject iks = Instantiate(puk.gameObject, new Vector3(x, y, z), Quaternion.identity); iks.SetActive(true); } void Start() { audioSource = GetComponent(); 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(); } else{ hudcko.won = true; } } hudcko.collectedcubes = collectedcubes; hudcko.collectedcubes_max = maxcubes; } }