Some help anyone?

Hey guys, I just made a huge leap in progress, so I thought I would share it, and maybe get some help with a few things.

Ok, here is my scene setup:

I have a floor.

I have my first Person Controller

I have three 3d text objects: Right answer, Wrong answer (x3), all children of an empty named Answer

I have a cube (trigger) in front of the text.

I have a script attached to the cube:

var IsTrigger : boolean; //Is the character in the trigger? Yes/no Switch   

var RightAnswer : boolean = false;

var target : RightAnswer;

function Start(){ //What happens on start?

	Screen.lockCursor = true; //mouse locked and hidden

	renderer.enabled = false; //The object this is attached to is visible.

	

		GameObject.Find("Answers").renderer.enabled = false;

        GameObject.Find("Answers/1").renderer.enabled = false;

        GameObject.Find("Answers/2").renderer.enabled = false;

        GameObject.Find("Answers/3").renderer.enabled = false;

}





function OnTriggerEnter(other : Collider){ //when we walk in to the object, which is a trigger, what happens?

    IsTrigger = true; //the IsTrigger variable gets turned on!





        GameObject.Find("First Person Controller").GetComponent(MouseLook).enabled = false; //Find our Character, and turn of  Y mouselook



        GameObject.Find("First Person Controller").GetComponent(CharacterMotor).enabled = false; //Find our character, and turn of walking script



        GameObject.Find("First Person Controller/Main Camera").GetComponent(MouseLook).enabled = false; //find the main camera under our character and turn off X mouselook.

        GameObject.Find("Answers").renderer.enabled = true;

        GameObject.Find("Answers/1").renderer.enabled = true;

        GameObject.Find("Answers/2").renderer.enabled = true;

        GameObject.Find("Answers/3").renderer.enabled = true;

        Screen.lockCursor = false; //The mouse is now free to move around the screen

        

}





function OnTriggerExit(other : Collider){ //What happens when we exit the trigger?



    IsTrigger = false; // Switch of IsTrigger, which disables all of the above.



}



// This will enable the character to walk into an objective, and have the question appear, in which he has 3 seconds to answer the question. He can not move,

// or look around. The mouse becomes able to move, so he can choose the correct math question. //ADD ISQUESTIONRIGHT\\

This makes it so that when I walk into the invisible cube, it makes my answer object (and all of its children) visible. It then freezes my movement, my camera movement, and disables the mouselock. I can now click one of the 3d text objects. Each of these has this script attached:

var RightAnswer : boolean;

var SecondsToWait : int = 3;

var LevelToLoad : String;



function OnMouseUp(){

		if(RightAnswer){

	 		GameObject.Find("First Person Controller").GetComponent(CharacterMotor).enabled = true;         // Turn back on

        	GameObject.Find("First Person Controller").GetComponent(MouseLook).enabled = true;				//Turn back on	

        	GameObject.Find("First Person Controller/Main Camera").GetComponent(MouseLook).enabled = true; //Turn back on

			Screen.lockCursor = true;  // Lock our mouse up again

			GameObject.Find("Answers").renderer.enabled = false;

        	GameObject.Find("Answers/1").renderer.enabled = false;

        	GameObject.Find("Answers/2").renderer.enabled = false;

        	GameObject.Find("Answers/3").renderer.enabled = false;

        	var questionA = gameObject.FindWithTag("Destroy"); Destroy(questionA);

		}



		if(RightAnswer == false){

			print("Wrong Answer!");

			yield WaitForSeconds(SecondsToWait);

			Application.LoadLevel(LevelToLoad);

		}

		

}

that basically destroys all the objects, and unfreezes the character IF it is the right answer. If it is the wrong answer, it loads a level.

So what happens, The character walks forward, and his controls suddenly freeze, and four buttons appear in front of him. He clicks the right one, and he moves on, and if he clicks the wrong one, he gets booted back.

I just have a few problems. I have everything in my scene that I want destroyed tagged “destroy”. It deletes all the questions, but it leaves the cube, even though it is tagged destroy. Do I have to do separate tags for each object? Or can I reuse the same on on multiple ones?

Second problem. How can I get it to load the begging of the level the character is on? I don’t know how to somehow make it so that it loads the last level that was loaded, which will put the character in the begging of the level he is ON.

thanks guys.

You are using FindWithTag which only returns a single game object. You want to use FindAllObjectsWithTag which will give you an array of objects.

Thanks a lot for that. Anything on the lastlevel bit though?

Edit: I get an error when using that.

MissingMethodException: Method not found: 'UnityEngine.GameObject.FindAllObjectsWithTag'.
Boo.Lang.Runtime.DynamicDispatching.MethodDispatcherFactory.ProduceExtensionDispatcher ()
Boo.Lang.Runtime.DynamicDispatching.MethodDispatcherFactory.Create ()
Boo.Lang.Runtime.RuntimeServices.DoCreateMethodDispatcher (System.Object target, System.Type targetType, System.String name, System.Object[] args)
Boo.Lang.Runtime.RuntimeServices.CreateMethodDispatcher (System.Object target, System.String name, System.Object[] args)
Boo.Lang.Runtime.RuntimeServices+<Invoke>c__AnonStorey12.<>m__6 ()
Boo.Lang.Runtime.DynamicDispatching.DispatcherCache.Get (Boo.Lang.Runtime.DynamicDispatching.DispatcherKey key,

Really loving what they have done with the code quoting system :slight_smile:

I am capable of technically answering the question but I am not able to understand what it is you are asking. Can you rephrase it in a different manner?

I probably wrote the function name incorrectly. Working on iPad so do not have the docs open in front of me. Read the docs for the exact function.

Thanks, I found it. As to the last level thing, this is what I’m trying to accomplish.

I need a respawn system, that remembers what level your on, and restarts it, rather than just loading a level.

I can do Application.LoadLevel(whatever), but how can I get it to just restart the level I’m on at the moment?

Application.LoadLevel(Application.loadedLevel) will reload the last level that was loaded.