Hi, I just downloaded Unity and I am currently working through a tutorial on a simple game.
I am trying to assign text(I went Create → UI → Text, I hope that was the right one) to this script, but drag and drop as well as typing the name of my text object won’t work. I have a feeling that it is because the create menu in hierarchy has UI > Text instead of GUI, since that’s the only thing I think may be wrong. My script is the following:
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour
{
public float speed;
public GUIText countText;
private int count;
void Start()
{
count = 0;
setCountText();
}
void setCountText()
{
countText.text = "Count:" + count.ToString ();
}
void Update()
{
}
void FixedUpdate()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVeritcal = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVeritcal);
rigidbody.AddForce(movement * speed * Time.deltaTime);
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "PickUp")
{
other.gameObject.SetActive(false);
count = count + 1;
setCountText();
}
}
}