This C# Isn’t showing the Count Text.
Also, a timer should be working
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using UnityEngine.SceneManagement;
public class PlayerController : MonoBehaviour {
private Rigidbody rb;
private int count;
public Text countText;
// Using same speed reference in both, desktop and other devices
public float speed =1000;
void Main ()
{
// Preventing mobile devices going in to sleep mode
//(actual problem if only accelerometer input is used)
Screen.sleepTimeout = SleepTimeout.NeverSleep;
}
void Update()
{
if (SystemInfo.deviceType == DeviceType.Desktop)
{
// Exit condition for Desktop devices
if (Input.GetKey("escape"))
Application.Quit();
}
else
{
// Exit condition for mobile devices
if (Input.GetKeyDown(KeyCode.Escape))
Application.Quit();
}
}
void FixedUpdate ()
{
if (SystemInfo.deviceType == DeviceType.Desktop)
{
// Player movement in desktop devices
// Definition of force vector X and Y components
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
// Building of force vector
Vector3 movement = new Vector3 (moveHorizontal,0.0f,moveVertical);
// Adding force to rigidbody
rigidbody.AddForce(movement * speed * Time.deltaTime);
}
else
{
// Player movement in mobile devices
// Building of force vector
Vector3 movement = new Vector3 (Input.acceleration.x, 0.0f, Input.acceleration.y);
// Adding force to rigidbody
rigidbody.AddForce(movement * speed * Time.deltaTime);
}
}
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag ("Pick Up"))
{
other.gameObject.SetActive (false);
count = count + 1;
SetCountText ();
}
if (other.gameObject.CompareTag ("Finish"))
{
SceneManager.LoadScene ("You Win!!!");
}
float timeLeft = 60.0f;
timeLeft -= Time.deltaTime;
if (timeLeft < 0)
{
SceneManager.LoadScene ("Game Over");
}
}
void SetCountText ()
{
countText.text = "Items Collected: " + count.ToString ();
if (count >= 3)
{
SceneManager.LoadScene ("Level 2");
}
}
}