I need to have a script where it will find all the objects under the tag “Pickup” so that It can put it to this text I have saying how many you’ve collected so far out of total and I want it to find the total when the game starts.
using UnityEngine;
strong textusing System.Collections;
public class Player_Controller : 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();
}
}
//Below here is where I make the level complete text come up.
void SetCountText()
{
countText.text = "Count: " + count.ToString ();
if (count >= 12 //<-- I want to make a variable replace total right here. )
{
winText.text = "Level Complete";
}
}
}