- Home /
Please follow a tutorial to learn how to write scripts.
Help with trigger zone
Hi, I have a little car game, something similar to Hill Climb Racing, and I have a trigger zone at the end of the level. I tried some scripts that I found arond, but nothing worked. This is what I need: I have the car named "PickUp" and at the end of the level the trigger. When the car enters in the trigger zone, I want to load the menu. I tried to do a scri't myself, but didn't work. Thx.
Answer by legion_44 · Jun 29, 2014 at 03:12 PM
Give Your car object (the one with collider if Your car is made from more parts) a tag "Car" and try this: (to add a tag, go to Edit->Project settings->Tags and Layers, and then in Yor car gameObject inspector, select Tag to Car)
class LevelEnd : MonoBehaviour
{
void OnTriggerEnter(Collider c)
{
if(c.CompareTag("Car"))
{
Application.LoadLevel("Level Name"); //Or Application.LoadLevel(0); where 0 is level index in build settings
}
}
}
And attach this script to trigger.
Hope that helps,
Paul
It gives me error at line 8 unexpected symbol and line 10 parsing error, a don't know anything about C#. Actually I know how it looks but writing the code...
Could the error be due to the fact that you typed his commented code on a separate line?
Omit the red text: "//Or Application.LoadLevel(0); where 0 is level index in build settings"
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Trigger GUI with a key when colliding (C#)? 1 Answer
Help with hiding an object on trigger enter 1 Answer
Animation triggered by an animation? 1 Answer
How do I make it so that when you pass over a line, you switch levels? 3 Answers