- Home /
Turning off character control when window open
I'm trying to ignore all user input when my inventory window is open and am having some problems with it.
Here is the code I'm using:
public void AllowPlayerControl(bool allowControl)
{
CharacterMotor motor = GetComponent<CharacterMotor>();
MouseLook mouseLook = GetComponent<MouseLook>();
motor.enabled = allowControl;
mouseLook.enabled = allowControl;
}
This works in stopping the player moving the character and horizonal mouse movement but the player is still able to move the mouse vertically. The character controller itself was taken directly from the standard assets scripts for first person controller. What else do I need to disable to fix this?
Answer by jashan · Oct 24, 2010 at 06:25 PM
One approach to finding out what is missing: While playing, have a look at the hierarchy and inspect the objects that might be relevant (cameras, player objects) and see which components are attached. Then disable those and see if it has the desired effect.
Another approach: Code review ... review your code to find out what is causing the effect of vertical mouse-movement. Then disable that.
I've disabled every script attached to the character. Is there any way of disabling the CharacterController component? I can't see any 'Active' or 'Enabled' properties in the scripting reference...
As the CharacterController is just a kind of collider, it shouldn't be the thing causing your problems. Can you edit your question and include the scene hierarchy? If the scene hierarchy is too complex to post here, you might try creating a simple repro case (that's usually also a good way to find out what the problem is - but it's also often a bit of work): Create the simplest possible scene that shows the unwanted behavior you see. Also, it might be interesting to see the implementation of $$anonymous$$ouseLook (it's probably the most likely candidate for the trouble).
Answer by Drakmyth · Dec 27, 2012 at 10:21 PM
The MouseLook script on the First Person Controller handles horizontal rotation, but there is also a MouseLook script attached to the Main Camera inside the First Person Controller that handles the vertical rotation. This is because when you look left/right the entire First Person Controller rotates, but when you look up/down, only the camera rotates.
Your answer
Follow this Question
Related Questions
Mouse movement swings character around in circles 1 Answer
How can I save MouseLook position in this script ? 0 Answers
rotate player towards the mous 1 Answer
How to Disable Mouse and Character movement? (Javascript) 1 Answer
Why does my mouselook sensitivity change depending on resolution? (C#) 1 Answer