I wanna alter the variable of senstivityX and sensitvityY of player. MouseController script is attached to the player and camera of the player.
The player is in another scene.
I wanna change the mouse sensitivity from the Main Menu Scene using Slider.
I'm using DontDestroyOnLoad() function to accomplish this. But, the problem is show me the error > Object not set to an reference.
Actually, the MENU script (it's in MainMenu scene) tries to search the player within Main Menu scene, whereas player in another scene("FPS_Battle").
I don't know what am I doing wrong. Even though I'm using the DontDestroyOnLoad() function.
Here's menu script which is assigned to an empty gameobject and it's in Main Menu scene.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class Menu : MonoBehaviour {
private Slider sens;
private GameObject playerSens;
private GameObject CameraSens;
void Start(){
DontDestroyOnLoad (this.gameObject); //dont destroy this gameobject so that it can be used further in another scene.
sens = GameObject.FindGameObjectWithTag ("sensX").GetComponent (); //access the slider compoenent in scene1(menu);
playerSens = GameObject.FindGameObjectWithTag ("Player"); //search for the player gameobect of player in scene2
CameraSens = GameObject.FindGameObjectWithTag ("CameraSens"); //search for the camera gameobject of player in scene2
}
public void Senstivity(){
playerSens.GetComponent ().sensitivityX = sens.value; //change the sensitivity of player - X axis - **
CameraSens.GetComponent ().sensitivityY = sens.value; //change the senstivity of camera - Y axis
}
//When I change the senstivity it shows from error that object not reference set. **
}
}
I don't wanna use STATIC keyword as it poses some problems for me.
Thanks!!
↧