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 Trent_GD · Dec 01, 2013 at 05:28 AM · javascriptguidrawtexture

GUI.Drawtexture Overlaping Other GUI.Drawtexture.

Hey There,

I've have spent some time writing an Achievement script using GUI.Drawtexture for a game I'm working on at University. An I have run into some trouble an I'm hoping someone here may be able to help me. Essentially, the script I have renders a GUI.Drawtexture when a specific condition is made, though when two conditions are achieved at the same time the script will only draw one of the textures instead of one after the other or both at the same time. Any help would be great and thank you in Advanced.

Here is the code I am currently working on (I'm using Javascript):

Also, the youGotAchivement, is called in another script.

 #pragma strict
 
 var textureH : int = 150;    // Texture Height
 var textureW : int = 100;    // Texture Width
 
 var textures: Texture2D[];; // 2D Texture Array for Challanges
 
 static var youGotAchievement01 : boolean; // Turns on/off Achievement - Hold Combo for 10 Seconds
 static var youGotAchievement02 : boolean; // Turns on/off Achievement - Remain Untouched for 5 Seconds
 static var youGotAchievement03 : boolean; // Turns on/off Achievement - Kill 5 Enemies in 2 Seconds
 
 private var originalWidth = 2560.0; // define here the original resolution
 private var originalHeight = 1440.0; // you used to create the GUI contents
 
 private var scale : Vector3;
 
 function Start () 
 {
     Destroy (gameObject, 3);
 }
 
 function OnGUI()
 {
     scale.x = Screen.width/originalWidth; // calculate hor scale
     scale.y = Screen.height/originalHeight; // calculate vert scale
     scale.z = 1;
     
     var svMat = GUI.matrix; // save current matrix
     // substitute matrix - only scale is altered from standard
     GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, scale);
     
     
     if(youGotAchievement01 == true)
         {
           GUI.DrawTexture(new Rect(Screen.width / originalWidth + (originalWidth ) - 150,Screen.height / originalHeight + (originalHeight ) - 100,textureH, textureW), textures[0]); // enable texture
         }
     if(youGotAchievement02 == true)
         {
           GUI.DrawTexture(new Rect(Screen.width / originalWidth + (originalWidth ) - 150,Screen.height / originalHeight + (originalHeight ) - 100,textureH, textureW), textures[1]); // enable texture
         }
     if(youGotAchievement03 == true)
         {
           GUI.DrawTexture(new Rect(Screen.width / originalWidth + (originalWidth) - 150,Screen.height / originalHeight + (originalHeight ) - 100,textureH, textureW), textures[2]); // enable texture
         }
     GUI.matrix = svMat; // restore matrix
 }
Comment
Add comment · Show 2
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 Tomer-Barkan · Dec 01, 2013 at 05:29 AM 0
Share

Well, you're drawing them all in the exact same position, so how do you expect to see more than one at a time?

Please explain in more detail what you expect to happen when more than one condition is true.

avatar image Trent_GD · Dec 01, 2013 at 07:34 AM 0
Share

Say the player unlocks 2 achievements at the same time, I want to have it so that one achievement will pop up for the set time, then followed by the other achievement that was unlocked.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Tomer-Barkan · Dec 01, 2013 at 11:58 AM

What you can do, is keep a list of all the achievements that you want to show, and show them one after another for a set amount of time. I'm not strong in javascript, but I'll try:

 private var achievements : Texture2D[];
 private var displayedAchievement : Texture2D = null;
 private var displayAchievementUntil : float = 0;
 private var displayTime : float = 3;
 
 function AddAchievement(texture : Texture2D) {
     achievements.push(texture);
 }
 
 function OnGUI() {
     if (Time.time >= displayAchievementUntil && displayedAchievement != null) {
         // stop displaying achievement
         displayedAchievement = null;
     }
 
     if (displayedAchievement == null && achievements.length > 0) {
         // display next achievement
         displayedAchievement = achievements[0];
         achievements.splice(0, 1);
         displayAchievementUntil = Time.time + displayTime;
     }
 
     if (displayedAchievement != null) {
         // display achievement texture
         GUI.DrawTexture(new Rect(Screen.width / originalWidth + (originalWidth) - 150,Screen.height / originalHeight + (originalHeight ) - 100,textureH, textureW), displayedAchievement); 
     }
 }

Call AddAchievement with the texture of the achievement you want to dispaly. It will automatically display it for displayTime seconds and then display the next one.

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

17 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

Related Questions

Texture on center bottom of screen 3 Answers

Setting Scroll View Width GUILayout 1 Answer

How to change rect size? 2 Answers

[Closed]GUI.DrawTexture inside GUI.DrawTexture 1 Answer

Fade between textures in the same script? 3 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