Player Controller Script:
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class PlayerController : MonoBehaviour {
public float speed;
public Text countText;
public Text winText;
private Rigidbody rb;
private int count;
void Start ()
{
rb = GetComponent<Rigidbody> ();
count = 0;
SetCountText ();
winText.text = "";
}
void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
float jumpers = 0;
if (Input.GetKeyDown (KeyCode.Space))
{
jumpers = 15.0f;
}
Vector3 movement = new Vector3 (moveHorizontal, jumpers, moveVertical);
rb.AddForce(movement * speed);
}
void OnTriggerEnter(Collider other)
{
if(other.gameObject.CompareTag("Pickup"))
{
other.gameObject.SetActive (false);
count = count + 1;
SetCountText ();
}
}
void SetCountText ()
{
countText.text = "Count: " + count.ToString ();
if (count >= 49)
{
winText.text = "You win!";
}
}
}
Rotator Script:
using UnityEngine;
using System.Collections;
public class Rotator : MonoBehaviour {
void Update ()
{
transform.Rotate (new Vector3 (90, 90, 90) * Time.deltaTime);
}
}
I have created a Particle System, but I need to figure out how to make use of them when the ball touches a collectable object ( tagged Pickup ). I know I should use Instantiate, and that would probably before “other.gameObject.SetActive (false);”, but I just can’t work it out? Can you help? I uploaded a picture also.