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 TrewSx · Apr 29, 2013 at 10:01 PM · javascripttexturegui.window

How to make a Texture change in GUI.Window

Hi i am trying to change my Texture inside GUI.Window when the Player is hit or he does a hit to the enemy and have there no Texture if he does nothing from these two.

So far i've got the Textures working, but when i am in the game and do nothing the first Texture is always loaded inside my Window, i want to have that window clear and Texture to appear only when i do a hit or receive a hit.

 #pragma strict
 var mtSkin: GUISkin;
 
 var hudPanelWidth : int;
 var hudPanelHeight : int;
 
 var attackicon : Texture;
 var defenceIcon : Texture;
 
 
 private var _hudWindowRect                    :    Rect = new Rect(0,Screen.height - 90,250,100);
 private static var _hudWindowID                :    int   = 3;
 
 
 private var console : Console;
 private var player : GameObject;
 
 function Start () {
     
     player = GameObject.FindGameObjectWithTag("Player");
     console = player.GetComponent(Console);
     
      
 }
 
 
 function OnGUI () {
     
     GUI.skin = mySkin;
     GUI.backgroundColor = Color.black;
     GUI.color = Color.white;  
     _hudWindowRect = GUI.Window(_hudWindowID, _hudWindowRect, AttackPanelHUD, GUIContent (console.enemyAttackLabel, defenceIcon) || GUIContent (console.playerAttackLabel, attackicon )); 
     
 
 }
 
 function AttackPanelHUD (_hudWindowID) {
     
             
 //    var temp : String = "";    
 //    temp = console.enemyAttackLabel;
 //
 //    
 //    
 //    var temp2 : String = "";
 //    temp2 = console.playerAttackLabel;
     
     
     
 }
 

 
Comment
Add comment · Show 1
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 Fornoreason1000 · Apr 29, 2013 at 10:08 PM 0
Share

please format your code

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Fornoreason1000 · Apr 29, 2013 at 10:12 PM

OK just tell OnGUI or Console or whatever to only draw any of the textures you your doing one of those things, if not it will do nothing. (use IF's) do this before you determine which texture to display

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
avatar image TrewSx · Apr 29, 2013 at 10:19 PM 0
Share

i'll try that, thanks

avatar image
0

Answer by TrewSx · May 01, 2013 at 06:45 PM

It's working now, take a look

 #pragma strict
 var AttackHUDSkin : GUISkin;
 
 var hudPanelWidth : int;
 var hudPanelHeight : int;
 
 var attackicon : Texture;
 var defenceIcon : Texture;
 
 
 private static var _hudWindowID1            :    int   = 3;
 private static var _hudWindowID2            :    int   = 4;
 
 
 private var _displayAttackAndDefenceTextures : boolean = true;
 private var _displayAttackTextures : boolean = false;
 private var _displayDefenceTextures : boolean = false;
 
 private var console : Console;
 private var player : GameObject;
 
 function Start () {
     
     player = GameObject.FindGameObjectWithTag("Player");
     console = player.GetComponent(Console);
     
     
      
 }
 
 
 function OnGUI () {
     
     GUI.BeginGroup (Rect (0,Screen.height - 150,500,150));
     //GUI.Box (new Rect (0,0,250,75), "Bottom-left");
     //GUI.Box (new Rect (0,75,250,75), "Bottom-left2");
     
     GUI.skin = AttackHUDSkin;
     GUI.backgroundColor = Color.gray;
     GUI.color = Color.white;  
     
     var _hudWindowRect1                    :    Rect = new Rect(0,Screen.height - 115,250,65);
     var _hudWindowRect2                    :    Rect = new Rect(0,Screen.height - 50,250,75);
     
     
     if (_displayAttackAndDefenceTextures) {
     
     _hudWindowRect1 = GUI.Window(_hudWindowID1, _hudWindowRect1, AttackPanelHUD, GUIContent (console.enemyAttackLabel )); 
     _displayAttackTextures = true;
     
     _hudWindowRect2 = GUI.Window(_hudWindowID2, _hudWindowRect2, AttackPanelHUD2, GUIContent (console.playerAttackLabel )); 
     _displayDefenceTextures = true;
     
     }
     
     GUI.EndGroup();
 
 }
 
 function AttackPanelHUD (_hudWindowID) {
     if (_displayAttackTextures) {
     GUI.Button (Rect (0, 0, 65, 65), GUIContent (defenceIcon));
     
     }
 }
     
 function AttackPanelHUD2 (_hudWindowID) {
     if (_displayDefenceTextures == true) {
         GUI.Button (Rect (0, 0, 65, 65), GUIContent (attackicon));
     }
 }    
     
     
 
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

14 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

Related Questions

Not able to download textures from server... 0 Answers

Show part of a Texture, from the bottom 2 Answers

How to assign and find Textures by tag 1 Answer

Assigning UV Map to model at runtime 0 Answers

GUI.Window is not resizing properly when resolution is being changed 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