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 redteardrop · Sep 13, 2012 at 02:12 AM · guislideronguiwindow

slider inside window function not inside onGui

I have an OnGUI function with a window in it that works fine. I want to have a slider inside the window so I am putting it inside the function WindowFunction (windowID : int) that the window calls to, but it won't budge at all. I am using hSliderValue = GUI.HorizontalSlider (Rect (125, 160, 200, 30), hSliderValue, 0.0, 10.0); with a predefined variable of hSliderValue called before the function and the OnGUI. I put the same code in the OnGUI and it works, but not in the window call function. How can I get them to work together? thanks

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

Answer by redteardrop · Sep 13, 2012 at 04:39 AM

I suppose if this won't work I could use a variable for the position and have it check where the window is and change it relative to that, but I was hoping for a more elegant solution. Here is my code.

var position : int = 200;

var hScrollbarValue : float;
private var hSliderValue : float = 4.1;
function OnGUI ()
{
var windowRect = GUI.Window(0, Rect((Screen.width / 2) - (windowWidth / 2),
position,
windowWidth,
windowHeight),
WindowFunction, "Menu");
}

function WindowFunction (windowID : int) {
hScrollbarValue = GUI.HorizontalScrollbar (Rect (125, 125, 200, 30), hScrollbarValue, 1.0, 0.0, 10.0);
hSliderValue = GUI.HorizontalSlider (Rect (125, 160, 200, 30), hSliderValue, 0.0, 10.0);
}
was trying to get a scrollbar to work too since it's more the style I want, but same issue.

edit: Using what I said here using a variable for the position and sliding the window in and out with the buttons and sliders at the same time worked, but the buttons and sliders were behind the windwo so I needed one in the called function just to make it look good. That doubles the amount of buttons but is doable. My issue got fixed and it works properly now since I deleted buttons in another script in the OnGUI section. Apparently they were were conflicting each other for some reason. No idea why, there was nothing in the script that would suggest that.

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 aldonaletto · Sep 13, 2012 at 02:23 AM

You should post your code here! Anyway, the variable hSliderValue must be a member variable, which means that it must be declared outside any function. Inside OnGUI, don't use the keyword var before hSliderValue, or a temporary local variable with this name will be created (temporary variables only exist inside the function, being destroyed upon return). The code should be something like this:

// declare the variable outside any function: var hSliderValue: float = 0;

function OnGUI(){ // don't use "var" before the variable! hSliderValue = GUI.HorizontalSlider (Rect (125, 160, 200, 30), hSliderValue, 0.0, 10.0); } If this doesn't solve your problem, edit your question and post your script.

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

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

10 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

Related Questions

GUI.Window only shows for one frame under all circumstances 2 Answers

Slider & Button Interaction Problem 0 Answers

how to get Gui in OnGUI function to resize with the window? 1 Answer

How do I customize or reshape GUI vertical slider? 0 Answers

OnGUI Button 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