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 Dmellott · Mar 11, 2013 at 01:06 AM · texturesonmousedown

Each consequtive mouse click removes a different Gui.Texture?

I am trying to figure out how to make a script so that each consecutive OnMouseDown or otherwise removes a different texture.

Specifically the energy-bar on the top left. The red panels are seperate png images, with the casing being it's own png image.

I need to make it so that when you shoot the gun, it removes a piece of the energy bar but I have no idea how to make OnMouseDown register different pieces for consecutive clicks or if that is even possible?

Any advice would be greatly appreciated!

Note: I am using Javascript and I have uploaded a picture of my EnergyBarScript.

alt text

alt text

energybar.jpg (64.2 kB)
energybarscript.jpg (70.8 kB)
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
0
Best Answer

Answer by Khada · Mar 11, 2013 at 02:29 AM

A pseudo example:

 var activeBars : int = 10;
 
 function Update()
 {
     if(Input.GetMouseButtonDown(0))
         --activeBars;
 }
 
 function OnGUI()
 {
     GUI.depth = 1;

     switch(activeBars)
     {
         case 10: GUI.DrawTexture(Rect(15,10,50,48), EnergybarTop); //top bar
         case 9: /* draw next bar */ ;
         case 8: /* draw next bar */ ;
         case 7: /* draw next bar */ ;
         case 6: /* draw next bar */ ;
         case 5: /* draw next bar */ ;
         case 4: /* draw next bar */ ;
         case 3: /* draw next bar */ ;
         case 2: /* draw next bar */ ;
         case 1: GUI.DrawTexture(Rect(19,385,44,40), EnergybarBottom); //bottom bar
     }

     GUI.depth = 0;
 }
Comment
Add comment · Show 10 · 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 Dmellott · Mar 11, 2013 at 03:07 AM 0
Share

It's telling me Int cannot be assigned to.

avatar image Khada · Mar 11, 2013 at 03:32 AM 0
Share

Woops, I put --int; ins$$anonymous$$d of --activeBars;. I edited my answer. Try again.

avatar image Dmellott · Mar 11, 2013 at 04:54 AM 0
Share

I plugged the names of the textures into the / draw top bar /; section and so on and now it's telling me "Expressions in statements must only be executed for their side-effects."

avatar image Dmellott · Mar 11, 2013 at 04:54 AM 0
Share

var EnergybarShell: Texture; var EnergybarTop: Texture; var EnergybarBottom: Texture; var Energybar$$anonymous$$iddle2: Texture; var Energybar$$anonymous$$iddle3: Texture; var Energybar$$anonymous$$iddle4: Texture; var Energybar$$anonymous$$iddle5: Texture; var Energybar$$anonymous$$iddle6: Texture; var Energybar$$anonymous$$iddle7: Texture; var Energybar$$anonymous$$iddle8: Texture; var Energybar$$anonymous$$iddle9: Texture; var PDA: Texture;

var activeBars : int = 10;

function Update() { if(Input.Get$$anonymous$$ouseButtonDown(0)) --activeBars; }

static var guiDepth : int = 0;

function OnGUI(){ GUI.depth = guiDepth;

//EnergyBars GUI.depth = 1; GUI.DrawTexture(Rect(15,10,50,48), EnergybarTop);

GUI.depth = 1; GUI.DrawTexture(Rect(17,55,50,44), Energybar$$anonymous$$iddle2);

GUI.depth = 1; GUI.DrawTexture(Rect(14,100,50,40), Energybar$$anonymous$$iddle3);

GUI.depth = 1; GUI.DrawTexture(Rect(16,142,50,31), Energybar$$anonymous$$iddle4);

GUI.depth = 1; GUI.DrawTexture(Rect(14,177,51,40), Energybar$$anonymous$$iddle5);

GUI.depth = 1; GUI.DrawTexture(Rect(16,219,49,39), Energybar$$anonymous$$iddle6);

GUI.depth = 1; GUI.DrawTexture(Rect(19,258,44,45), Energybar$$anonymous$$iddle7);

GUI.depth = 1; GUI.DrawTexture(Rect(19,300,44,45), Energybar$$anonymous$$iddle8);

GUI.depth = 1; GUI.DrawTexture(Rect(19,340,44,45), Energybar$$anonymous$$iddle9);

GUI.depth = 1; GUI.DrawTexture(Rect(19,385,44,40), EnergybarBottom);

//EnergyBarShell GUI.depth = 0; GUI.DrawTexture(Rect(5,5,70,420), EnergybarShell);

//PDA GUI.depth = 1; GUI.DrawTexture(Rect(665,420,300,300), PDA);

switch(activeBars) { case 10: EnergybarTop ; case 9: Energybar$$anonymous$$iddle2 ; case 8: Energybar$$anonymous$$iddle3 ; case 7: Energybar$$anonymous$$iddle4 ; case 6: Energybar$$anonymous$$iddle5; case 5: Energybar$$anonymous$$iddle6 ; case 4: Energybar$$anonymous$$iddle7 ; case 3: Energybar$$anonymous$$iddle8 ; case 2: Energybar$$anonymous$$iddle9; case 1: EnergybarBottom; }

}

avatar image Dmellott · Mar 11, 2013 at 04:54 AM 0
Share

That is what I have so far, not sure if I am using your script improperly.

Show more comments

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

11 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

Related Questions

Import (Plz Help) 1 Answer

Instantiating material due to calling renderer.material during edit mode. 1 Answer

How to get at runtime the path of a Texture assigned in the editor ? 0 Answers

unable to fix texture on model in unity 1 Answer

Can you load images from outside the resources folder? 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