using UnityEngine;
using System.Collections;

public class BalanceBoardTest : MonoBehaviour {

    private Plane plane;
    private Color[] colours;
	// Use this for initialization
	void Start () {
        plane = new Plane(Vector3.back, transform.position);
        colours = new Color[5];
        colours[0] = Color.red;
        colours[1] = Color.blue  ;
        colours[2] = Color.green ;
        colours[3] = Color.gray  ;
        colours[4] = Color.yellow;
    }

    // Update is called once per frame
    void Update () {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            float dist;
            if (plane.Raycast(ray, out dist))
            {
                transform.position = ray.GetPoint(dist);
                Rigidbody rigidbody = GetComponent<Rigidbody>();
                rigidbody.drag = 5.0F;
                Renderer renderer = GetComponent<Renderer>();
                renderer.material.color = colours[Random.Range(0, colours.Length)];
            }
        }
    }
}
