- Home /
When ai (capsule) touches gameobject reset scene. The code does not work, and there is no errors any suggestions
#pragma strict
var collisionObject : GameObject;
function OnCollisionEnter(collision : Collision)
{
if (collision.gameObject == collisionObject)
{
Application.LoadLevel("0");
}
}
function Update () {
}
Answer by zviaz · May 11, 2015 at 03:30 PM
Try this. Attach this script to the AI. The object that, when collided with, will cause a reset is tagged as "DeathBall". You obviously don't have to use DeathBall from this example. Then check if the AI collides with a game object tagged as "DeathBall", if so reset the scene. Note that one of the game objects (either the AI or the collidable object) must have a rigid body component attatched to it for the script to work.
My guess is your code does not work because you do not specify what the game object is that, when collided with, will reset the scene.
function OnCollisionEnter(collision : Collision)
{
if (collision.gameObject.tag == "DeathBall")
{
Application.LoadLevel("0");
}
}
#pragma strict
var collisionObject : GameObject;
function OnCollisionEnter(collision : Collision)
{
if (collision.gameObject.tag == "FirstPersonController")
{
Application.LoadLevel("0");
}
}
function Update () {
}
Your answer
Follow this Question
Related Questions
Button press does not work in some of the scenes as intended. 0 Answers
How to reset a scene from collision with a GameObject? 0 Answers
access gameobject via touch 1 Answer
Rhythm Game - Not all notes on touch are changing sprite. (easy to read) 2 Answers
Best workflow for DontDestroyOnLoad method regarding Unity Editor? 1 Answer