- Home /
Question by
martinhalldin · Nov 20, 2012 at 03:39 PM ·
playercollidersontriggerentermouselookunity4
Lock camera (on) ontriggerenter
I have a problem, when i walk into a trigger area i want my mouselook to be disabled and i'v tried scripts like these:
function OnTriggerExit(other : Collider)
{
GetComponent("MouseLook").enabled = false;
}
but they wont work! i don't get errors but it just wont work.
I'm using Unity4 if that's whats causing it...
Comment
Best Answer
Answer by Democre · Nov 20, 2012 at 04:17 PM
First, if you want to disable when entering a trigger, you should probably be using
function OnTriggerEnter(other : Collider)
{
...
}
Second, ensure that this trigger script is on the same object that you are expecting to have the MouseLook component. Your code right now is assuming this. If the MouseLook is on the colliding object you would need to do this
function OnTriggerEnter(other : Collider)
{
var mouseLook = other.GetComponent("MouseLook") as MouseLook;
if(mouseLook != null) {
mouseLook.enabled = false;
}
}
I swear to god if i'm born an idiot again... and thank you, that was the answer i was looking for.