ok so…i have this sphere with tag “Player”…and i want to load another level whenever my sphere collides with another sphere…but when other thing collide with the sphere…it still loads the next level…for example…in oe of the levels i have a cube and whenever that cube collides with the other sphere…it loads the next level…:/…heres my script…please help i really need help with this! thanks -goatria
var levelToLoad: int;
var WaitTime = 3;
function Start(){
levelToLoad = Application.loadedLevel+1;
}
function OnTriggerEnter(hit : Collider){
if(hit.gameObject.tag == "Player"){
yield WaitForSeconds(WaitTime);
}
Application.LoadLevel(levelToLoad);
}
Let me get this straight, you want when a player hits an object for it to load a new level. But you also want an object that hits the player NOT to load a level?
Your further complicating it by putting a script on that object that says… “When ever I touch a player, load a level”
You can’t do both.
The only way to accomplish what you are saying is to test the relative speed between the objects. If the player has more relative speed, then load a level.
no…i want to load the next level…when the player hits with the sphere the script is attached to…but in my scene th is a cube that when it hits it it loads the level…and i don’t want that…i want for it to load ONLY when the player collides with it
This is why tabbing is a good practice in coding… Here is your script (reload is in red)
var levelToLoad: int;
var WaitTime = 3;
function Start(){
levelToLoad = Application.loadedLevel+1;
}
function OnTriggerEnter(hit : Collider){
if(hit.gameObject.tag == "Player"){
yield WaitForSeconds(WaitTime);
}
[COLOR="red"]Application.LoadLevel(levelToLoad);[/COLOR]
}
here is your code fixed…
var levelToLoad: int;
var WaitTime = 3;
function Start(){
levelToLoad = Application.loadedLevel+1;
}
function OnTriggerEnter(hit : Collider){
if(hit.gameObject.tag == "Player"){
//yield WaitForSeconds(WaitTime);
[COLOR="red"]Application.LoadLevel(levelToLoad);[/COLOR]
}
}
Now, I commented the yield, because you can’t do a yield in anything but a coroutine and the Start functions. So here is the code with a proper wait and load coroutine…
var levelToLoad: int;
var WaitTime = 3;
function Start(){
levelToLoad = Application.loadedLevel+1;
}
function OnTriggerEnter(hit : Collider){
if(hit.gameObject.tag == "Player"){
StartCoroutine(WaitAndLoad(WaitTime));
}
}
function WaitAndLoad(t){
yield WaitForSeconds(t);
Application.LoadLevel(levelToLoad);
}
AAAHHHH thank you so much!!!..finally it worked!!! im so happy!!! now i can continue with my project…thanks everyone that replyied but mostly thank you “BigMisterB” im so happy!!! XD…