Hi, Im starting to develop games with Unity, I know one thing or another about programming logic but I
m still a noob.
My question is: in Unity first tutorial (roll a ball) there`s a counter that shows off how many objects we have “collected”.
The problem is that we have to use a code with exact number of objects collected to show us that we won, and I was wondering if we can change that to something like: if all objects in “Pickups” Hierarchy object are inactive, it would show us we won.
(I hope it’s not confusing), here is the code for reference:
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour
{
public float speed;
public GUIText countText;
public GUIText winText;
private int count;
void Start ()
{
count = 0;
SetCountText();
winText.text = "";
}
void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
rigidbody.AddForce(movement * speed * Time.deltaTime);
}
void OnTriggerEnter(Collider other)
{
if(other.gameObject.tag == "PickUp")
{
other.gameObject.SetActive(false);
count = count + 1;
SetCountText();
}
}
void SetCountText ()
{
countText.text = "Count:" + count.ToString();
if (count >= 7)
{
winText.text = "you win";
}
}
}