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 Twun · Jun 05, 2014 at 01:50 PM · javascriptfunctionguitextureifwhile

How do I call a script or a function to be active 'while'a GUITexture is displayed?

I must start by apologising the lack of convention within my script. I have never studied any programming language and I am trying to teach myself the basics of UnityScript.

What I have is a function called Freeze which disables character movement and mouse look scripts.

This works perfectly when combining a RaycastHit with a GetKey. This then displays a button that can be clicked which on doing so displays the GUITexture.

What I need is for the Freeze function to be called while the GUITexture is onscreen, preventing any inadvertent movement of the character.

Here is my script so far.

 #pragma strict
 
 function Freeze(){
 
 Screen.showCursor = true;
 
 var ml = GameObject.Find("Main Camera");
 
 GetComponent(MouseLook).enabled = false;
 
 ml.GetComponentInChildren(MouseLook).enabled = false;
 
 GetComponent(FPSInputController).enabled = false;
 
 GetComponent(CharacterMotor).enabled = false;
 }
 
 
 function UnFreeze(){
 
 var ml = GameObject.Find("Main Camera");
 
 Screen.showCursor = false;
 
 GetComponent(MouseLook).enabled = true;
 
 ml.GetComponentInChildren(MouseLook).enabled = true;
 
 GetComponent(FPSInputController).enabled = true;
 
 GetComponent(CharacterMotor).enabled = true;
 }
 
 
 function OnGUI(){
 
 var go = GameObject.Find("InfoScreen");
 
 go.GetComponent(MyGUI).enabled = true;
 }
 
 
 function offGUI () {
 
 var go = GameObject.Find("InfoScreen");
 
 go.GetComponent(MyGUI).enabled = false;
 }
 
 
 function Start () {}
 
 
 
 var linkToInfoBox : InfoBox;
 
 
 function Update () {
 
 var go = GameObject.Find("InfoScreen");
 
 Screen.showCursor = false;
 
 var ray : Ray = Camera.main.ViewportPointToRay(Vector3(0.5,0.5,0));       
       
 var Hit : RaycastHit;
 
 //var ray = Camera.main.ScreenPointToRay;//(Input.mousePosition);
 
 go.GetComponent(MyGUI).enabled = false;
 
 go.GetComponent(InfoBox).enabled = false;
 
 var texup = go.GetComponent(GUITexture).enabled;
 
 
 
 Debug.DrawRay(ray.origin, ray.direction * 5, Color.cyan);
 
 
 if(Input.GetKey(KeyCode.F))
 {
 Freeze();
 }
 else 
 {
 UnFreeze();
 }
 
                                                   
         for(Hit in Physics.RaycastAll(ray.origin, ray.direction, 5))
         {
     
             
                  if(Hit.transform.name == "BigTree")
                  {                      
                         OnGUI();
                         
                         Debug.DrawRay(ray.origin, ray.direction * 5, Color.red);
                         
                         
                         if((Hit.transform.name == "BigTree") && (Input.GetKey(KeyCode.E)))                        
                         {
                             Screen.showCursor = true;                            
                                                                                                                 
                             Freeze();
                             
                             go.GetComponent(InfoBox).enabled = true;    
                             
                             offGUI();    
                             
                             //linkToInfoBox.OnGUI ();
                             
                             }                        
                             else
                             {
                             UnFreeze();
                         }
                         
         
                             
                     //    GetComponent(Freeze).enabled = false;
                     //    tex.GetComponent(GUITexture).enabled = false;
                     //    }
                             
                     }
                 }                
 
         if (Input.GetMouseButtonDown(0))
         {
          go.GetComponent(GUITexture).enabled = false;         
         }
                         
 }          
                 

The InfoBox script is as follows

 #pragma strict
 
 var linkToInfoRaycast : InfoRaycast;
 
 
 
 function OnInfoGUI() 
 
 {
 
 var onTex = GetComponent(GUITexture).enabled;
 
 //var mygui = GetComponentInChildren(MyGUI).enabled;
 
 GUI.Label (Rect (400, 140, 300, 140), "Text");
 
 if (GUI.Button (Rect (400,300,150,50), "Click for information"))
 
         {
         GetComponent(GUITexture).enabled = true;
         
 
         GUI.Label(Rect(500, 300, 300, 40), "Click to exit");
         }
         
         
     }


I have tried using an If statement nested inside the button that says if ( GetComponent(GUITexture).enabled = true) but this does not work as I sure you are all well aware.

While loops caught my attention but I have not been able to set the conditions correctly for this either.

If anyone has an idea where I might be able to call the Freeze function while the GUITexture component is active I would be very grateful to hear.

Apologies again for the messy script.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Twun · Jun 10, 2014 at 11:29 AM

Solved.

Nested Ifs were causing the problem.

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

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

javascript equivalent of Action? 0 Answers

Performance Optimization ~Function Update: Loop or Once ? 5 Answers

BCE0023: No appropriate version of 'UnityEngine.Random.Range' for the argument list '(System.Object)' was found. 0 Answers

Call GUITexture and script 1 Answer

Need help with If/else statement. 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