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 Gambit 3 · Mar 24, 2011 at 12:31 PM · pauseflashlightproximitymouselock

help please :S? im confusing myself.

hey guys :)

i feel ashamed that im confusing myself here :) and im probably over thinking but heres what im trying to do.

Lock the cursor to the middle of the screen Hide the cursor when not in a dialog/gui Press e on a cylinder, it pops up with a GUI, unhide the cursor and unlock the cursor Press a button on the GUI and it closes the GUI menu, Hides and unlocks the cursor.

this is what iv managed to do: Confuse myself Hide the cursor (i had it locked but i wrecked it) When you click the screen it unhides the cursor (unintentional) When you click the button on the GUI it doesnt lock or hide the cursor.

all this may seem like i have no idea what im doing..but i do, iv just confused myself and you will see how when you look at the code:

Script attached to the player object:

var LightToggled : boolean = false; var IsPaused : boolean = false; var Lockit : boolean = true; var Showit : boolean = false;

function Start() { };

function Update() { Screen.showCursor = Showit; Screen.lockCursor = Lockit;

 if (Input.GetKeyDown ("f")){
     if (LightToggled == true){
         LightToggled = false;
     }
     else{
         LightToggled = true;
     };
 };  
 GameObject.Find('Player').GetComponent('Light').enabled = LightToggled;

 if (Input.GetKeyDown ("escape")){
     PauseGame();
 };  

};

function OnGUI() {

 GUI.Box(Rect(Screen.width/2, Screen.height/2-15, 1, 1), '');

 if (IsPaused == true){

     var ResumeButton : boolean = GUI.Button(Rect(Screen.width/2, Screen.height/2, 175, 20), "Resume Game");
     var VisitWebsite : boolean = GUI.Button(Rect(Screen.width/2, Screen.height/2 + 25, 175, 20), "Visit the Website");
     var MainMenu : boolean = GUI.Button(Rect(Screen.width/2, Screen.height/2 + 25 + 25, 175, 20), "Main Menu");
     var QuitButton : boolean = GUI.Button(Rect(Screen.width/2, Screen.height/2 + 25 + 25 + 25, 175, 20), "Exit");

     GameObject.Find('Player').GetComponent('MouseLook').enabled = false;
     GameObject.Find('Player').GetComponent('CharacterMotor').enabled = false;

     if (QuitButton){
         Application.Quit();
     };

     if (ResumeButton){
         IsPaused = false;
         Time.timeScale = 1.0;
         Screen.showCursor = false;
     };

     if (VisitWebsite){
         Application.OpenURL("www.google.com");
     };

     if (MainMenu){
         Application.LoadLevel(0);
     };

 }
 else{
     GameObject.Find('Player').GetComponent('MouseLook').enabled = true;
     GameObject.Find('Player').GetComponent('CharacterMotor').enabled = true;
     return;
 };

};

function PauseGame() { if (IsPaused == true){ IsPaused = false; Screen.showCursor = false; Screen.lockCursor = true; } else{ IsPaused = true; Screen.showCursor = true; Screen.lockCursor = false; };

};

Script attached to the NPC (Cylinder):

var LookingAt : boolean = false; var QuestMenu = false; var Swsi : boolean = false; // should we show it var Swli : boolean = true; // should we lock it

var Player : GameObject; var proximity : int = 3;

var dist = Vector3.Distance(Player.transform.position, transform.position);

function Update() {

 GameObject.Find('Player').GetComponent('Player').Lockit = Swli;
 GameObject.Find('Player').GetComponent('Player').Showit = Swsi;

 if (dist < proximity) {
     if (Input.GetKeyDown ("e") && LookingAt == true){
             QuestMenu = true;
     }
     else{
         return;
     };
 };

};

function OnGUI() {

 GameObject.Find('Player').GetComponent('MouseLook').enabled = false;
 GameObject.Find('Player').GetComponent('CharacterMotor').enabled = false;

 if(QuestMenu == true){

     Swli = false;
     Swsi = true;

     GUI.Box(Rect((Screen.width/2) - (150/2), Screen.height/2, 150, 75), "Hi :D");

         if (GUI.Button(Rect((Screen.width/2) - (150/2) + 5, Screen.height/2 + 30 , 140, 25), "Hai :D")){
             QuestMenu = false;

             Swsi = false;
             Swli = true;

             GameObject.Find('Player').GetComponent('MouseLook').enabled = true;
             GameObject.Find('Player').GetComponent('CharacterMotor').enabled = true;
         };

     Swsi = true;
     Swli = false;
 }
 else{       
     return;
 };

};

function OnMouseEnter() { LookingAt = true; };

function OnMouseExit() { LookingAt = false; };

if you can shorten the code but still make it work and/or fix the problem/s that would be much appreciated :) thank you

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Gambit 3 · Mar 24, 2011 at 12:58 PM

k i fixed it a little...still the bug where, when you spawn your mouse isnt in the center..you click and its off the screen.

i should add that im testing this in unity..im not compiling it an running it.

new code for the cylinder:

var LookingAt : boolean = false; var QuestMenu = false; var Swsi : boolean = false; // should we show it var Swli : boolean = true; // should we lock it

var Player : GameObject; var proximity : int = 3;

var dist = Vector3.Distance(Player.transform.position, transform.position);

function Update() {

 GameObject.Find('Player').GetComponent('Player').Lockit = Swli;
 GameObject.Find('Player').GetComponent('Player').Showit = Swsi;

 if (dist < proximity) {
     if (Input.GetKeyDown ("e") && LookingAt == true){
             QuestMenu = true;
     }
     else{
         return;
     };
 };

};

function OnGUI() {

 if(QuestMenu == true){

     Swli = false;
     Swsi = true;

     GameObject.Find('Player').GetComponent('MouseLook').enabled = false;
     GameObject.Find('Player').GetComponent('CharacterMotor').enabled = false;

     GUI.Box(Rect((Screen.width/2) - (150/2), Screen.height/2, 150, 75), "Hi :D");

         if (GUI.Button(Rect((Screen.width/2) - (150/2) + 5, Screen.height/2 + 30 , 140, 25), "Hai :D")){
             QuestMenu = false;

             GameObject.Find('Player').GetComponent('MouseLook').enabled = false;
             GameObject.Find('Player').GetComponent('CharacterMotor').enabled = false;

             Swsi = false;
             Swli = true;
         };
 }
 else{       
     return;
 };

};

function OnMouseEnter() { LookingAt = true; };

function OnMouseExit() { LookingAt = false; };

Oh yes, i forgot to add in the original post that when you press escape...you cant see the mouse :( and when you click the buttons nothing happens

Comment
Add comment · 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
0

Answer by Joshua · Apr 30, 2011 at 03:33 AM

"k i fixed it a little...still the bug where, when you spawn your mouse isnt in the center..you click and its off the screen."

function Start () {

 Screen.lockMouse = true;

}

Comment
Add comment · 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

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

No one has followed this question yet.

Related Questions

Accessing Variables from other scripts 1 Answer

How to start gradient for dissolve shader at specific spot on mesh 0 Answers

Flashlight turning off, but not back on again? 4 Answers

How to pickup flashlight with "E" key ? 1 Answer

Recharging battery script, help 1 Answer


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