I had a simple idea to turn on and off the mouse look controls so that you can use the mouse to click on objects then turn it back on so you can walk around like a normal FPS.
First problem is that Mouse Look script is in C# and i dont know C# at all. Having a hard enough time figuring out JS So i went and found one converted to JS on the Unity Scripting Wiki. There is an odd issue with it tho, in that whenever you are moving with arrow keys, mouse look doesn’t work. once you stop you can start again.
How i wanted to go about this was a simple variable hooked up to the space bar key. Turning on and off the entire mouse look script. Is there a better way to go about this?
i have looked through the forums a lot, found some similar things in C# and a few threads about it in JS but nothing i was able to complete and get the full understanding of.
I was using the scripts off of your link. I tried both of the mouse look scripts. MouseLookPro doesn’t seem to work correctly, gives me an error even when i just paste it into its own script to test it. The 2nd one is the one i said i was having other problems with. Regarding the mouse look disengaging when you press movement keys.
thats what i want to do. There is always a bunch of little barriers to get through tho
I was going to try and use the MouseLook scripts off of the wiki but they just arent working 100% right for me. So iv just decided to make the script i need in C# since the original MouseLook that is in the defualt folder of the project is what i need, just the wrong language.
Im making 1 script to put out a on/off variable.
static public var SpaceDown : int = 0;
function Update ()
{
if (Input.GetKeyDown ("space") SpaceDown == 0)
{
Debug.Log("Mouse Look On");
SpaceDown = 1;
}
else if (Input.GetKeyDown ("space") SpaceDown == 1)
{
Debug.Log("Mouse Look Off");
SpaceDown = 0;
}
}
This is working fine. But its in JS of course.
Then i will just want to add in a comparison like this into every line of the original mouse look.
Original if (axes == RotationAxes.MouseXAndY)
updated with comparison
if (axes == RotationAxes.MouseXAndY MouseLookKiller.SpaceDown == 0)
I know thats probably not right, im reading trying to figure out how to translate what i want to do into C#. I wonder why they decided to make some of the baseline scripts in C# vs JS.
Just my two cents, but the value of what Tom suggested is that, when your mouse look script is disabled, you won’t be running a useless update function. It may be a trifle of performance, but good practice.
@MBomberZ1: and the advantage of my suggestion is your user won’t have to hold down the space bar. They tap it once they’re in “click on stuff mode”, they tap it again they’re back in “mouse look” mode.
i see what you mean and i completely agree i should do that, but i dont know how to go about shutting down a scipt via another script or where to start. Like i said im still just in the learning phases of JS, feeling very overwhelmed at times but slowly making progress. Thanks for the suggestion, ill search around the forums and see if i can find something similar.
This would best be done in its own script. If you added this sort of code to the existing script you could turn it off but not back on as once you disable a component it won’t get Update events anymore thus blocking the ability to turn itself back on!
You can even make this script and attach it to the same game object.
With a little searching on those great pointers you gave me. Its now working perfectly! Thanks so much. Here are the two scripts i made for it to work.
I had to make two because i needed both the Mouselook scripts to turn on. There is one on the Controller, and one on the camera.
public static var SpaceDown1 : int = 0;
function Update ()
{
if (Input.GetKeyDown ("space") SpaceDown1 == 0)
{
Debug.Log("Mouse Look On"); transform.GetComponent(MouseLook).enabled = false;
SpaceDown1 = 1;
}
else if (Input.GetKeyDown ("space") SpaceDown1 == 1)
{
Debug.Log("Mouse Look Off");
transform.GetComponent(MouseLook).enabled = true;
SpaceDown1 = 0;
}
}
public static var SpaceDown2 : int = 0;
function Update ()
{
if (Input.GetKeyDown ("space") SpaceDown2 == 0)
{
Debug.Log("Mouse Look On");
transform.GetComponent(MouseLook).enabled = false;
SpaceDown2 = 1;
}
else if (Input.GetKeyDown ("space") SpaceDown2 == 1)
{
Debug.Log("Mouse Look Off");
transform.GetComponent(MouseLook).enabled = true;
SpaceDown2 = 0;
}
}
Maybe there is a more simplified way to make these but im just glad they are working haha. Thank you for your help.[/code]
You can do both of those in one script, you’ll just need to first reference the other game object/camera, and from there disable the script component as needed. But either way you’re up and running so that’s good! Keep havin’ fun.