The problem with this script is that the 'OnCollisionEnter' function is not being called when the ball collide with the collider..can any one help me to find whats the wrong in this script..?? using UnityEngine; using System.Collections;
public class BallSpawnTest : MonoBehaviour
{
private Vector3 initialPos;
private Quaternion originalRotation;
// Called when the game starts
void Start()
{
// Remeber the ball's initial position. Later we will use it to restore the ball after every kick
initialPos = transform.position;
originalRotation = transform.rotation;
}
void Update ()
{
Debug.Log("update function called");
// Reset();
}
void OnCollisionEnter(Collider collide) {
if(collide.gameObject.name=="Sphere")
{
Debug.Log("collied");
Reset();
}
}
private IEnumerator RestartBall()
{
yield return new WaitForSeconds(5);
Debug.Log("in restart bal function");
transform.position = initialPos;
transform.rotation = originalRotation;
}
public void Reset()
{
StartCoroutine(RestartBall());
rigidbody.velocity = Vector3.zero;
rigidbody.angularVelocity = Vector3.zero;
Debug.Log("function called");
}
}
asked
Jul 03 '12 at 12:55 PM
Hims
50
●
3
●
11
●
17