Roll a Ball

My first project, a very basic Unity project where the goal is to collect all the yellow cubes and dodge the red ones.

My extra assignment for this project was to add the red cubes and write a code that would decrease the score by one if you'd pick up a red cube.
I also added a rotator to the cubes just to make it a bit nicer looking.

Roll a ball editor

Roll a ball ingame

GameController.cs

using UnityEngine; using System.Collections; public class GameController : MonoBehaviour { public GameObject player; private Vector3 offset; // Use this for initialization void Start () { offset = transform.position - player.transform.position; } // Update is called once per frame void Update () { transform.position = player.transform.position + offset; } } PlayerController.cs using UnityEngine; using UnityEngine.UI; using System.Collections; public class PlayerController : MonoBehaviour { public float speed; public Text countText; public Text winText; public Text losingText; private Rigidbody rb; private int count; void Start () { rb = GetComponent(); count = 0; SetCountText (); winText.text = ""; losingText.text = ""; } void FixedUpdate() { float moveHorizontal = Input.GetAxis("Horizontal"); float moveVertical = Input.GetAxis("Vertical"); Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical); rb.AddForce(movement * speed); } void OnTriggerEnter(Collider other) { if (other.gameObject.CompareTag("Pick Up")) { other.gameObject.SetActive(false); count = count + 1; SetCountText (); } if (other.gameObject.CompareTag("Pick Up Bad")) { other.gameObject.SetActive(false); count = count - 1; SetCountText(); } } void SetCountText() { countText.text = "Count: " + count.ToString(); if (count >= 12) { winText.text = "You Win"; } if (count <= -1) { losingText.text = "You Lost"; } } } Rotator.cs
using UnityEngine; using System.Collections; public class Rotator : MonoBehaviour { // Update is called once per frame void Update () { transform.Rotate(new Vector3(15, 30, 45) * Time.deltaTime); } }