How do I get that my curling moves one time (push him one time). An other problem is that I want to reset the scene when the curling is not in the win zone and the speed about 0.
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour
{
public float speed;
public TextMesh wintext;
private Rigidbody rb;
void Start ()
{
rb = GetComponent<Rigidbody>();
wintext.text = "";
}
void FixedUpdate ()
{
//Push object every time//
if (Input.GetMouseButtonUp (0))
{
float h = Input.GetAxis ("Mouse X");
float v = Input.GetAxis ("Mouse Y");
Vector3 movement = new Vector3 (h, 0.0f, v);
rb.AddForce (movement * speed);
}
}
//When object is in win zone --> go to main Screen""
void OnTriggerStay(Collider other)
{
if (other.gameObject.CompareTag ("Win Zone"))
{
speed = GetComponent<Rigidbody> ().velocity.magnitude;
if (speed < 0.005)
{
gameObject.GetComponent<Rigidbody> ().constraints = RigidbodyConstraints.FreezeAll;
wintext.text = "You Win";
//A 5 sec pause would be great here//
Application.LoadLevel(0);
}
}
}
}