Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by bobolat · Nov 05, 2014 at 08:26 PM · cameracursorviewlock

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

alt text

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();
 
     }
 }

2222.jpg (189.4 kB)
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image bobolat · Nov 06, 2014 at 04:37 AM 0
Share

i think like that too..but i have no idea how to disable when popup=true..

3 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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;
 } 
Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image bobolat · Nov 10, 2014 at 05:04 AM 0
Share

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);





avatar image EvilTak · Nov 10, 2014 at 09:21 AM 0
Share

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.

avatar image bobolat · Nov 10, 2014 at 09:55 AM 0
Share

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??

avatar image EvilTak · Nov 10, 2014 at 09:57 AM 0
Share

In eq1 script. Just use the same code in my answer, but ins$$anonymous$$d of Camera.main, put your gameobject variable.

avatar image bobolat · Nov 10, 2014 at 10:03 AM 0
Share

i love u man..thnks for ur fast response..solved

avatar image
1

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image bobolat · Nov 07, 2014 at 02:56 PM 0
Share

how to use your method ??i cant get you..sorry

avatar image
0

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

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image bobolat · Nov 07, 2014 at 02:48 PM 0
Share
  #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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges