- Home /
lock camera to when open popup screen
hello there..i have gym environment here which is every equipment inside the environment got button attached..when i click the button it will show popup GUI window..my question is how to prevent my camera view moving around while i explore the popup window?? pic shown is the popup screen..when i want to play the the video while my cursor go into play button i want the camera not moving around follow my cursor..sorry if u cant understand me..my English too bad..help me
here's my popup gui window script i use to attached at the button "click here"
using UnityEngine;
using System.Collections;
public class eq1 : MonoBehaviour {
// Use this for initialization
private bool PopUp;
public string Info;
public MovieTexture movie_eq1;
void OnMouseDown()
{
PopUp = true;
}
void DrawInfo()
{
//Rect rect = new Rect (20,20, 600, 400);
Rect close = new Rect (800,20,20,20);
Rect play = new Rect (100, 360, 50, 25);
Rect pause = new Rect (150, 360, 50, 25);
Rect stop = new Rect (200, 360, 50, 25);
if (PopUp)
{
//GUI.BeginGroup (new Rect (Screen.width, Screen.height, 800, 400));
//content
GUI.Box(new Rect(20, 20, 800, 400), "Lat Pulldown");
//GUI.Box(rect, Info);
GUI.DrawTexture(new Rect(30, 50, 400, 300), movie_eq1);
GUI.Box(new Rect (450,50,300,200), "A weight machine is an exercise machine used\nfor weight training that uses gravity as the\nprimary source of resistance and a combination\nof simple machines to convey that resistance to\nthe person using the machine. Each of the simple\nmachines (pulley, lever, wheel, incline) changes\nthe mechanical advantage of the overall machine\nrelative to the weight.");
//playbutton
if (GUI.Button(play,"play"))
{
//Debug.Log("playvideo");
//renderer.material.mainTexture = movie_eq1;
movie_eq1.Play();
}
//pause
if (GUI.Button(pause,"pause"))
{
//renderer.material.mainTexture = movie_eq1;
movie_eq1.Pause();
}
//stopbutton
if (GUI.Button(stop,"stop"))
{
movie_eq1.Stop();
}
//guiTexture.texture.Play();
if (GUI.Button(close,"X"))
{
PopUp = false;
movie_eq1.Stop();
//Debug.Log("close");
}
//GUI.EndGroup ();
}
}
void OnGUI()
{
DrawInfo();
}
}
i think like that too..but i have no idea how to disable when popup=true..
Answer by EvilTak · Nov 09, 2014 at 03:56 AM
You should just get the main camera and disable the FPS script if Popup is true. In eq1:
if(Popup) {
Camera.main.GetComponent<YourFPSScript>().enabled = false;
//rest of your code
}
else
{
Camera.main.GetComponent<YourFPSScript>().enabled = true;
}
i got ur code..but it seems not work with the obejct..i gode this error..
Object reference not set to an instance of an object
my button to popup the screen not clickable at all..
this code i use to rotate the main camera for FPSscript
//rotationmouse
float rotleftright = Input.GetAxis ("$$anonymous$$ouse X")*mouseSensitivity;
transform.Rotate (0, rotleftright, 0);
verticalRotation -= Input.GetAxis("$$anonymous$$ouse Y") * mouseSensitivity;
verticalRotation = $$anonymous$$athf.Clamp(verticalRotation, -upDownRange, upDownRange);
Camera.main.transform.localRotation = Quaternion.Euler(verticalRotation, 0, 0);
Oh so you have your fps script on a different object. So make a public gameobject variable, assign it the gameobject which has your fps script in the inspector, and put that variable in place of Camera.main in my code.
can u make it more detail??i cant get u..sorry im newbie..where to put that game object variable??at eq1 script or fps script??
In eq1 script. Just use the same code in my answer, but ins$$anonymous$$d of Camera.main, put your gameobject variable.
Answer by Zypherr7 · Nov 06, 2014 at 12:53 AM
You can disable the screen from moving by putting in a variable that turns on when the popup comes up. Then wherever you have the mouse input code just put:
if(PopUp = false) return;
That is the easiest fix that I can think of at the moment.
p.s. you will also need to make the PopUp variable accessible by both classes.
Answer by bobolat · Nov 06, 2014 at 05:00 AM
how to disable the camera movement while the variable of the camera from the other script which is FPS script??this is the script..
//rotationmouse
float rotleftright = Input.GetAxis ("Mouse X")*mouseSensitivity;
transform.Rotate (0, rotleftright, 0);
verticalRotation -= Input.GetAxis("Mouse Y") * mouseSensitivity;
verticalRotation = Mathf.Clamp(verticalRotation, -upDownRange, upDownRange);
Camera.main.transform.localRotation = Quaternion.Euler(verticalRotation, 0, 0);
i have no idea how to disable it and make the class variable can accessible both classes
#pragma strict
var Obj : GameObject;
function Start () {
Obj.SetActive(false);
}
function OnTriggerEnter ()
{
Obj.SetActive
(true);
Screen.lockCursor = false;
}
function OnTriggerExit ()
{
Obj.SetActive(false);
Screen.lockCursor = true;
//Destroy(gameObject);
}
this code i isue to trigger the button when player near the object..can i lock the player cmaera while the player near the object to??plzz give me an advise to stop my player camera moving around while im in the interactive screen
Your answer
Follow this Question
Related Questions
Camera Lock. 1 Answer
Screen.lockCursor messes my rotation 1 Answer
Lock the screen 1 Answer
Viewer position lost in Space. How to get back to scene? 1 Answer
How do I calculate a view matrix using Matrix4x4.LookAt? 2 Answers