Quantcast
Viewing latest article 3
Browse Latest Browse All 9

Answer by KBurchfiel

Here's how I'm doing it in my game. I have two barriers that I define as game objects (wall1 and wall2). I count the 'grape' pickups that I've gotten so far, and I then tell the game to destroy wall1 and wall2 once the count reaches 3 and 6, respectively. You just have to tell the game what your "wall1" and "wall2" are in the inspector. I also include a user interface element for counting the pickups and giving a 'win' message. Most of this is copied and pasted from Unity's RollABall tutorial. using UnityEngine; using UnityEngine.UI; using System.Collections; public class ExtraScript : MonoBehaviour { public GameObject wall1; public GameObject wall2; public Text countText; public Text winText; private int count; void Start() { count = 0; SetCountText (); winText.text = ""; } void OnTriggerEnter(Collider other) { if (other.gameObject.CompareTag ("Grape")) { other.gameObject.SetActive(false); count = count + 1; SetCountText(); } } void Update() { if (count == 3) { Destroy(wall1); } if (count == 6) { Destroy(wall2); } } void SetCountText () { countText.text = "Count: " + count.ToString(); if (count >= 7) { winText.text = "You have won!"; } } } End script

Viewing latest article 3
Browse Latest Browse All 9

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>