I have a quiz type game in which you walk up to a door, get asked a question, and if you get the question right the door gets destroyed and you move on. If not it locks and you have to find a way around. Currently everything works fine with the exception then when your picking your answer the mouselook is spinning your character around. I've gotten it so I disable the mouseLook script on entering the trigger but if the person gets the question right and the wall gets destroyed, onTriggerExit never gets called to turn the mouseLook script back on. Any ideas?
Answer by BinaryCaveman
Aug 31, 2010 at 06:12 PM
First, make sure you are using the correct OnTriggerExit() syntax:
function OnTriggerExit(other : Collider)
// Disable MouseLook script
If you are, then why don't you try re-enabling the MouseLook script in the same function where you destroy the wall? That would seem more logical, unless you use OnTriggerExit() for other purposes in your game.
I'm still trying to learn how to change a variable on one gameObject script with a script from a different gameObject. IE: Disabling mouselook on the FPS controller with a script attached to the trigger. Perhaps thats the core of my problem that I need to learn.
You could use GameObject.Find("First Person Controller").GetComponent("MouseLook").enabled = true; to disable a MouseLook script attached to a GameObject named "First Person Controller".
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
No one has followed this question yet.
Trigger animation going crazy
Trigger on MeshCollider Only Seems To Work at Edges of Mesh
OnTriggerEnter and Exit seem to not be working
Is it bad to add a mouse Lock at MouseLook Script?
OnTriggerExit2D is not working