Disabling Mouse look on pause menu C#

Hello! I already have pause menu but i cant make mouse look disable please help :slight_smile:

And here is the script… ( İf you need this scirpt take it :slight_smile: )

using UnityEngine;
using System.Collections;

public class deneme : MonoBehaviour 
{ 
	
	bool pause = false;
	

	// Use this for initialization
	void Start ()
	{ 
		Time.timeScale = 1;
		Screen.lockCursor = true; 
	} 

	// Update is called once per frame 
	void Update () 
	{ 
		
		if(Input.GetKeyDown(KeyCode.Escape))
		{
			pauseDegistir();
		}
	}

	void OnGUI ()
	{
		GUI.Label(new Rect(10,10,100,200),"FlashLight");
		
		if( pause )
		{
			
			GUI.Box(new Rect(560,170,250,300), "MENU");
			
			if(GUI.Button(new Rect(610,210,150,50), " resume"))
			{
				pauseDegistir();
			}
			if(GUI.Button(new Rect(610,310,150,50), "Options"))
			{
				
			}
			if(GUI.Button(new Rect(610,410,150,50), "Quit"))
			{
				Application.LoadLevel(0);
			}	
		}
	}
	
	void pauseDegistir()
	{
		pause = !pause;
			
		if( pause )
		{
			Screen.lockCursor = false;
			Time.timeScale = 0;
		}
		else
		{
			Screen.lockCursor = true;
			Time.timeScale = 1;
		}
	}
}

You need a Reference to your MouseLook Script (I don’t know which one you use so I’ll just call it MouseLook, you likely have to replace it):

[SerializeField]
MouseLook mouseLook;

I’m using SerializeField here because that’s one of the things I’d not want to be public.

Then you can just enable or disable it:

mouseLook.enabled = false;

You need to drag your MouseLook-GameObject into the “Mouse Look” property of your script.

Thanks for your help but i didnt understand the drag… what and how i ll drag it. Sry im noob :slight_smile:

If you don’t know what a GameObject is, you should start over with the basics.

i know basics of course as you can see i did that script. by the way i think i didnt nderstand that your comment because of my english. You mean mouse look object is like first person controller for example?

There are basics and then there are basics. You cannot say that you know everything needed when you obviously don’t.

Anyway, there is a GameObject with your MouseLook Script on it. You’ll have to drag it from the hierarchy view to the property named “Mouse Look” that appears on your script in the inspector. With that, you build a reference to the component.

so im gona creat empty object called mouselook and gona drag my mouse look script on it. is it?

No. You already have a MouseLook script running somewhere that you wanted to disable. You have to drag that one in.

i get eror called null reference expection… and my mind blowed :slight_smile: i think im gona make u angry :slight_smile:

Can you post the current version of the script again?

using UnityEngine;
using System.Collections;

public class deneme : MonoBehaviour 
{ 
	
	bool pause = false;
	
	[SerializeField]

   MouseLook mouseLook;

	// Use this for initialization
	void Start ()
	{ 
		Time.timeScale = 1;
		Screen.lockCursor = true; 
	} 

	// Update is called once per frame 
	void Update () 
	{ 
		
		if(Input.GetKeyDown(KeyCode.Escape))
		{
			pauseDegistir();
		}
	}

	void OnGUI ()
	{
		GUI.Label(new Rect(10,10,100,200),"FlashLight");
		
		if( pause )
		{
			
			GUI.Box(new Rect(560,170,250,300), "MENU");
			
			if(GUI.Button(new Rect(610,210,150,50), " resume"))
			{
				pauseDegistir();
			}
			if(GUI.Button(new Rect(610,310,150,50), "Options"))
			{
				
			}
			if(GUI.Button(new Rect(610,410,150,50), "Quit"))
			{
				Application.LoadLevel(0);
			}	
		}
	}
	
	void pauseDegistir()
	{
		pause = !pause;
			
		if( pause )
		{
			Screen.lockCursor = false;
			Time.timeScale = 0;
			mouseLook.enabled = false;
		}
		else
		{
			Screen.lockCursor = true;
			Time.timeScale = 1;
			mouseLook.enabled = true;
		}
	}
}

Looks good, so the NullReferenceException comes from the Component that isn’t dragged into the property.

So i created empty object called mouseLook and draged in to the first person controller… is it
1316042--62161--$Başlıksız-1.jpg1316042--62162--$Başlıksız-2.jpg

Nah, you need to click on the object that has your script on it and check out the inspector (should be on the right).
There is a line that says “Mouse Look”. That’s where you have to drag the object into.

i see fianly but i cant add that empty obbjct to there?


1316048--62164--$Başlıksız-1.jpg

No, it has to be the object with the mouse look script in it.
Should be the first person controller and the Main Camera.
And since they’re two objects, you need another MouseLook variable in your script.

So whats the other variable? it gona be like

mouselook ml;

again?

Yup, just like the other one.

how im gona make that 2 object in 1?

You don’t.

Take some time to check out how the First Person Controller works.
Trying to use it in any way other than what you get out of the box without understanding how it works will get you nowhere.

The Mouse Look thing in the first person controller consists of two components on the FPS GameObjects.
One you’ll find when clicking on the “First Person Controller”, one on “Main Camera”.
These Components are what enable the player to look around using the Mouse.
Disable them (i.e. by unchecking the checkboxes besides their names) will disable Mouse Look.
To do this by script, you need two variables:

[SerializeField]
MouseLook mouseLookFirstPersonController;
[SerializeField]
MouseLook mouseLookMainCamera;

Then you drag the GameObjects “First Person Controller” and “Main Camera” from your Hierarchy to the properties in the inspector, add the enabled = false or true thing to both variables in the right place and that’s it.

As said, take some time to understand the Components you’re currently using before finally solving this. You’ll have more from that.

I’m out for tonight, good luck :slight_smile: