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 Rgalaxy · Jan 08, 2014 at 05:05 PM · javascriptguidrawtexture

[Closed]GUI.DrawTexture inside GUI.DrawTexture

maybe it is an odd question but what i try to accomplish here is..

i create a GUI.DrawTexture showing a whiteboard, and here's the code

 public var background1 : Texture;
 var btn_next : Texture;
 function OnGUI(){
 
     GUI.DrawTexture(Rect((Screen.width-(Screen.width/4*3))/2, 
             (Screen.height-(Screen.height/4*3))/2, //this is to center the Rect
                 Screen.width/4*3, Screen.height/4*3),background1);
 
     GUI.DrawTexture(Rect(200,100,40,20),btn_next);
      //btn_next must be at right-lower corner of whiteboard.
 }

and then i want to Draw again a texture of Next Button, but i want to Draw it Inside the background 1.. so i will not put it bluntly on the screen.. because it will cause the button takes different place on different mobile resolution..

Thanks before for any solution given here..

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 sath · Jan 08, 2014 at 11:03 PM

First of all:

Screen.width-(Screen.width/4*3))/2 = Screen.width *0.125

Screen.height-(Screen.height/4*3))/2 = Screen.height * 0.125

Screen.width/4*3 = Screen.width*0.75

Screen.height/4*3 = Screen.height*0.75

 #pragma strict
 
 var background1 : Texture;
 var btn_next : Texture;
 
 //background image dot start rect point
 var backX : float;
 var backY : float;
 
 //background image size
 var backWidth : float;
 var backHeight : float;
 
 //button image dot start rect point
 var buttonX : float;
 var buttonY : float;
 
 //button image size
 var buttonWidth : float;
 var buttonHeight : float;
 
 
 function OnGUI(){
 
     backX = Screen.width *0.125;
     backY = Screen.height * 0.125;
     backWidth = Screen.width*0.75;
     backHeight = Screen.height*0.75;
     
     buttonWidth = Screen.width*0.06;
     buttonHeight = Screen.height*0.05;
     buttonX = Screen.width *0.875 - Screen.width*0.06; //(backX + backWidth)- buttonWidth
     buttonY = Screen.height *0.875 - Screen.height*0.05; //(backY + backHeight)- buttonHeight
     
 
     GUI.DrawTexture(Rect(backX,backY,backWidth, backHeight),background1);
  
     GUI.DrawTexture(Rect(buttonX,buttonY,buttonWidth,buttonHeight),btn_next);
      //btn_next now it is at right-lower corner of whiteboard !!!
 }

another option if you have more than one buttons is to use GUI.BeginGroup

Comment
Add comment · Show 3 · 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 Rgalaxy · Jan 10, 2014 at 08:12 AM 0
Share

wow, this is good ! btw, @sath i create a serial of tutorial, that when i click next, the background image change to next image, does i should just call the new GUI.DrawTexture? or it's better for me to erase the last image first?

because i want the tutorial serial is able to go back and forward.. alt text

the background image is that board with the scratch (it was 1 image created in photoshop), and the next_btn is like that in the corner-right.. does the button should be a GUI.Button ins$$anonymous$$d?

capture.png (339.0 kB)
avatar image sath · Jan 10, 2014 at 03:20 PM 0
Share

Yes in this case the next_btn must be a GUI.Button(assume you know how)but if you have many backgrounds you must disable previous image before the next enabled and you need a previous_btn. You can use booleans in your OnGUI function were you can say if that btn pressed then next=true and GUI.backround = 1 etc.. If you feel that you need help on that it is better to open another Question as this one is answered and it is better to accept it as correct so everyone that may have the same problem can found a solution here..

avatar image Rgalaxy · Jan 11, 2014 at 12:58 PM 0
Share

Thanks you so much @sath, i will try it first with your guide and if i encounter any problem i will try to ask it here on another question ! :)

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

18 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

Related Questions

Fade between textures in the same script? 3 Answers

Texture on center bottom of screen 3 Answers

Setting Scroll View Width GUILayout 1 Answer

GUI.Drawtexture Overlaping Other GUI.Drawtexture. 1 Answer

How to change rect size? 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