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 LANDO · Feb 21, 2011 at 08:36 PM · javascriptguibutton

GUI Button Disappearing

I have four directional buttons in a scene to control a mars rover. When one button is clicked, the other remaining buttons disappear while the mouse is down. Has anyone exerienced a similiar problem? I'm probably overlooking something obvious, however any input is appreciated.

Here is my code for my main GUI (js) :

var motionDir: Vector3; // var ctrl: CharacterController;

var rover : GameObject;

private var GetKeyDown : boolean; private var buttonOn : boolean; private var windowOn : boolean;

var style : GUIStyle;

// BG/Template: var mainImage: Texture2D; var mainImageOffset = Vector2(0, 0);

//GUI active elements: var dPadOutline : Texture2D; var dPadLeft : Texture2D; var dPadRight : Texture2D; var dPadUp : Texture2D; var dPadDown : Texture2D;

var dPad : Texture2D; var gak : Texture2D; var histogram : Texture2D; var timerBG : Texture2D;

var position : Rect; var nativeVerticalResolution = 768;

//var btn1 : GUIStyle;

var cameraIris : MovieTexture;

var Active : boolean = true;

function OnGUI() {

 if  (!rover.animation.IsPlaying ("startUp") && !rover.animation.IsPlaying ("armDrillAnimation"))    

{

  if(GUI.RepeatButton (Rect(870,383,43,43), dPadUp, "button"))
 //if(GUI.RepeatButton (Rect(870,468,43,43), dPadUp, "label"))// || (Event.current.type == EventType.KeyUp && Event.current.keyCode == KeyCode.Alpha1))
 {
     Drive();
     return EventType.MouseDown;
 }


 if( GUI.RepeatButton(Rect(870,524,43,43), dPadDown, "button")) 
 {
     DriveReverse();
     return EventType.MouseDown;

 }

 if( GUI.RepeatButton(Rect(794,455,43,43), dPadLeft, "button")) // || (Event.current.type == EventType.KeyUp && Event.current.keyCode == KeyCode.Alpha1))
 { 
     TurnLeft();
     return EventType.MouseDown;
 }

 if( GUI.RepeatButton( Rect(932,455,43,43), dPadRight, "button"))
 {
     TurnRight();
     return EventType.MouseDown;
 }


 else if (!rover.animation.IsPlaying("drive") && rover.animation.IsPlaying("wheelTurnOut"))
 {
     rover.animation.CrossFade ("wheelTurnBack", 1);
     return EventType.MouseUp;
 }

 else
 {
     rover.animation.CrossFade ("staticPose");
     return EventType.MouseUp;   
 }  

//Draw bottom GUI section (main) DrawImageBottomAligned( mainImageOffset, mainImage); // main image.

}

/// Detects keys pressed and prints their keycode var e : Event = Event.current;

 if (e.isKey)
 {
     Debug.Log("Detected key code: " + e.keyCode);
 }


}

function Drive () { rover.animation.Blend ("drive", 0.3); rover.transform.Translate(Vector3.forward); Debug.Log("Available id: " + GUIUtility.GetControlID(FocusType.Passive)); print("DRIVE!!!"); }

function TurnLeft () { rover.animation.CrossFade ("wheelTurnOut", 0.05); rover.animation.Blend ("rotateLeft", 0.4); rover.transform.Rotate(Vector3.down); Debug.Log("Clicked the d-pad Left"); }

function TurnRight () { rover.animation.CrossFade ("wheelTurnOut", 0.05); rover.animation.Blend ("rotateRight", 0.4); rover.transform.Rotate(Vector3.up); Debug.Log("Clicked the d-pad Right");

}

function DriveReverse() { rover.animation.Blend ("driveInReverse", 0.3); rover.transform.Translate(Vector3.forward*-1); Debug.Log("Clicked the d-pad Down"); }

// Handles positioning of elements on screen function DrawImageBottomAligned (pos : Vector2, image : Texture2D) { GUI.Label(Rect (pos.x, nativeVerticalResolution - image.height - pos.y, image.width, image.height), image); }

function DrawLabelBottomAligned (pos : Vector2, text : String) { GUI.Label(Rect (pos.x, nativeVerticalResolution - pos.y, 100, 100), text); }

function DrawImageBottomRightAligned (pos : Vector2, image : Texture2D) { var scaledResolutionWidth = nativeVerticalResolution / Screen.height * Screen.width; GUI.Label(Rect (scaledResolutionWidth - pos.x - image.width, nativeVerticalResolution - image.height - pos.y, image.width, image.height), image); }

function DrawLabelBottomRightAligned (pos : Vector2, text : String) { var scaledResolutionWidth = nativeVerticalResolution / Screen.height * Screen.width; GUI.Label(Rect (scaledResolutionWidth - pos.x, nativeVerticalResolution - pos.y, 100, 100), text); }

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
1
Best Answer

Answer by _MGB_ · Feb 21, 2011 at 08:45 PM

You're returning from the OnGUI function if a button event is handled - therefore the other button code doesn't get run :)

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 LANDO · Feb 21, 2011 at 09:53 PM 0
Share

Jeez, that makes total since. So to maintain functionality and appearance I'm adding this under each respective button: GUI.Button(Rect0,0,0,0,), dPadUp, "button"); Is there a better approach? Thanks for your help!

avatar image _MGB_ · Feb 21, 2011 at 10:27 PM 0
Share

I'm not sure what you mean there, but just removing the return statements should sort things out.

avatar image LANDO · Feb 24, 2011 at 12:56 AM 0
Share

Removing the return statements fixes the problem of the buttons disappearing, however the RepeatButton functionality does not seem to stay intact doing so.

avatar image _MGB_ · Feb 24, 2011 at 02:04 PM 0
Share

Does this shed any light on your problem? http://forum.unity3d.com/threads/19527-RepeatButton-true-false

avatar image LANDO · Feb 24, 2011 at 06:52 PM 0
Share

That solves the button disappearing issue, my drive animation gets lost when using Update() and OnGUI() with the same method mentioned in the link you posted. I should be able to link up the animations which are triggered along with the button press, I'll keep working on it. Thanks again! :)

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

Javascript GUI.Button help, Error BCE0077 1 Answer

NGUI Repeat button In JavaScript problem 1 Answer

GUI.Button not appearing when called, no errors 1 Answer

GUIText Problem With MENU 1 Answer

Gui Button Solid 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