how to end a level?
I trying to end a level but i cant find a script to use. What script should i use to end the level when the player gets to a certain point?
Answer by heks · Dec 28, 2010 at 11:40 AM
Assuming the player represents a physical in-world RigidBody
and that it has the tag Player set, you can detect when it enters a trigger and then load your end level scene. Add the following code to a script attached to the trigger (Collider
) object:
function OnTriggerEnter(other : Collider)
{
if(other.gameObject.CompareTag("Player"))
{
Application.LoadLevel("EndLevel");
}
}
More information here:
http://unity3d.com/support/documentation/Manual/Physics.html http://unity3d.com/support/documentation/ScriptReference/Collider.html http://unity3d.com/support/documentation/ScriptReference/Application.LoadLevel.html
When i added this to my GameObject and walked into it the player just walked through the object.
How to Stop All Game Sound in All Scenes by simply pressing On/Off Button Hello I'm New in this field So please help me .. I just want to stop all music by pressing a simple button "Off" from main menu and Want to Start Again All Sound of the game By Pressing another button "On" also located on main menu ...
i designed 20 Levels,Scenes for my game and want to stop All sound of the game from main menu But i can only stop the Sound,$$anonymous$$usic that is on the main menu when i go to the next scenes,Level Sound is not $$anonymous$$ute .
I know its possible by using Void Awake() Function But i'm New So Please Give me the right solution,Logic ...Thanks
Answer by Jesus_Freak · Dec 28, 2010 at 01:24 AM
*if(transform.position = Bector)
{
Application.LoadLevel("nextlevel");
}
var Bector : Vector3;
But make sure you put the exact name of the level and add it to the build settings.
You probably want '=', not '=='. Also, due to floating-point imprecision, perfor$$anonymous$$g exact comparisons between vectors as you're doing here is almost always a bad idea. (Better to use a distance check in this case, or perhaps a trigger.)
You could use a trigger but could u explain how distance is better than comparing (==) to a point?
Because it is not very often that your transform.position will be complety equal to another point. Even if two objects may appear to be in the same place the floating point difference between the vectors could be .0001 which would make the check fail. Using if ( Vector3.Distance ( vec1, vec2 ) < threshold ) would therefore in most situations make more sense.
What $$anonymous$$ads said. (Also, even with a threshold distance, having to move your character to a single, specific point would likely be prohibitively difficult, so you'd probably want to use a distance threshold that was relatively large relative to the movement speed of the character. Of course at that point you're basically replicating the behavior of a spherical trigger, so if the player character has a collider associated with it, you might as well just use the trigger.)
Answer by joeybubble1 · Dec 28, 2010 at 11:28 AM
var levelToLoad: int;
function Start(){ levelToLoad = Application.loadedLevel+1; }
function OnTriggerEnter(collider : Collider) {
if(collider.gameObject.tag == "Player"){ Debug.Log("Player collided");
Application.LoadLevel(levelToLoad); } }
That's not very accurate, what if we just came from a main menu to some cheat menu and skipped some levels, then wouldnt it load the next level in line after cheat? Or what if their levels are messy in the build settings? Then it will go from level 1 to level 3 or something.
Answer by faramicool · Mar 04, 2013 at 04:07 PM
the best one is
var scene: string;
funvtion OnTriggerEntr{
application.LoadLevel(scene);
}