Does anyone know of a way that when my guy collides with something it loads the next level
its C# but really easy so… should not be a problem if you use other language!
void OnTriggerEnter(Collider other)
{
if (other.transform.root.CompareTag("Player"))
{
Application.LoadLevel("level2");
}
}
Whether your collider has “Is trigger” true or false, use functions OnCollision or OnTrigger (Enter/Stay/Exit).
Add a script on your player to detect collision.
function OnCollisionEnter (collision : Collision) {
if (collision.gameObject.name == "TriggerForNextLevel" || collision.gameObject.tag == "AnotherWayToDetectTrigger") {
Application.LoadLevel ("NextLevel");
}
}
it didn’t work. It show an error saying
Script can not be compiled. Please wait for compile of all the script
@AkilaeTribeit didnt work
And why wouldn’t it compile ? Where does the error show/point ? Comment these line out, can you compile again or is it still blocked ?
AkilaeTribe that post wasn’t pointed at you. But your idea didn’t work either
Ok, what’s this “something”, when you say collide with something ? Has it a tag ? What’s his name ?
the something is a gameobject. it’s tag is finish
Put this script on the object you control that is supposed to touch the finish object (Player Controller or anything else)
var nextScene : String;
function OnCollisionEnter (collision : Collision) {
if (collision.gameObject.tag == “finish”) {
Application.LoadLevel (nextScene);
}
}
Will it work?
…Eh ?
Who dares win. Special Air Service motto.
It didn’t work.
I found this script on the forums that would help. But it didn’t work. Can you see why it didn’t work?
function OnTriggerEnter(other : Collider){
Application.LoadLevel(0);
}
So I would need something like an if statment yes?
The gameobject with the script, it has a collider, right ? Look at the box “Is trigger”, is it ticked or not ?
If no, the collider is solid, you can bump on it, and it triggers the functions OnColliderEnter, OnColliderStay, OnColliderExit.
If yes, the collider is not solid, you can go through it, and it triggers the functions OnTriggerEnter, OnTriggerStay, OnTriggerExit.
Depending on whether the collider is trigger or not, you have to use the right functions.
How could I change it to collision on enter?
If the gameobject is a trigger:
function OnTriggerEnter(other : Collider)
{
Application.LoadLevel(*);
}
If it’s not:
function OnCollisionEnter (collision : Collision)
{
Application.LoadLevel(*);
}
-The script should be attached to the object the player is colliding with.
-
- = the name of the next level Application.LoadLevel(“TheName”) or the number of the level, you can find it in the build settings, for example Application.LoadLevel(1)
I hope you understand…[/code]
Ok thanks. Can you tell me which script goes on the player and on the object it’s colliding with again?
One of the scripts on the object, no script is needed on the player.
Will this script work with an NPC as well? If i want npc’s to be able to go from one level to the next. aka inside / out side or sector 1 / sector 5.