- Home /
Multiple Object Collider Detection to load new scene
Hi,
I am doing a hang glider game, whereby there's 5 rings in a terrain and the objective of the game is to fly through all the FIRST 4 rings first before you can go on to the 5th ring which will then load a new scene(A fast video and then a LEVEL Completed page )
I am currently having only one problem.
My hang glider can detect all individual rings i go through however, how do we set it up so that the NEW SCENE(video...) will only load IF I went through all of the FIRST 4 Rings, not any less. I Tried using public/static var and etc but it wont work as there's an error saying Unknown Identifier.HELP!!!
This is my current script for each of the first 4 ring
var airplane : GameObject; var Ring : GameObject; var ringscore1 : boolean;
ringscore1 = false ;
function OnTriggerEnter (other : Collider) { var distanceToRing; distanceToRing = Vector3.Distance(airplane.transform.position,
transform.position); print ("Distance to Ring: "+distanceToRing); //~ distance check
ringscore1 = true ;
}
and this is my current script for the 5TH Ring
function OnTriggerEnter (other : Collider)
{
if ((ringscore1 == true) && (ringscore2 == true) && (ringscore3 ==
true) && (ringscore4 == true)) { yield WaitForSeconds(3); Application.LoadLevel("scene6Landing"); } }
Can you edit your question and fix the formatting please? Your text is in code boxes, and your code is plaintext. Also, caps in the question title is a sure way to be noticed, but in negative light. The people here are giving their time to help, and (I would assume) don't much like being yelled at.
i apologise as i do not have experience in asking these questions and formatting. i improved it though. do help :)
Thanks! How you ask your question makes a big difference to the answers, and the overall quality of the wiki. How are you accessing the ringscore1 -> ringscore4 variables from the 5th ring script? Are you using GetComponent to look them up? I'd have suggested to use static vars, but you said you got an error - what was the exact error?
Answer by StephanK · Sep 02, 2010 at 08:01 AM
You are trying to access ringscore1...4 in your 5th ring script. I think ringscore1 is in another script so you can't access it through name only. What you have to do is GameObject.Find("Ring1").GetComponent("YourScript").ringscore1
However this is a bit clumsy, so a better idea would to make RingManager script with a bool[5] in it and update that each time one of the rings is hit. You could also put this array in the script for your final ring.