how to reset ball function after 10 second of delay
using UnityEngine; using System.Collections;
public class Ball : MonoBehaviour { public Vector3 launchVeclocity; //private const float RESET_TIME = 5.0f; // time to be taken for reset public bool inPlay = false;
private Vector3 ballStartPos;
private Rigidbody rigidBody;
private AudioSource audioSource;
// Use this for initialization
void Start () {
StartCoroutine(Example());
rigidBody = GetComponent<Rigidbody>();
//rigidBody.useGravity = false;
ballStartPos = transform.position;
}
public void Launch (Vector3 velocity)
{
inPlay = true;
rigidBody.useGravity = true;
rigidBody.velocity = velocity;
audioSource = GetComponent<AudioSource> ();
audioSource.Play ();
}
void Update() {
}
public void Reset() {
inPlay = false;
//yield return new WaitForSeconds (5);
transform.position = ballStartPos;
transform.rotation = Quaternion.identity;
rigidBody.velocity = Vector3.zero;
rigidBody.angularVelocity = Vector3.zero;
rigidBody.useGravity = false;
}
IEnumerator Example()
{
Reset ();
yield return new WaitForSeconds (10);
}
}
Comment