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 samz · Apr 04, 2013 at 11:30 AM · textureruntimeatlasezgui

ez gui change texture at runtime

How do I change the texture of an ezgui uiButton from its atlas during runtime. I found out that u need to call the .SetTexture () but im still confused on how to call this and what to do with it.

Thank you

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 robertbu · Apr 04, 2013 at 01:46 PM 1
Share

What kind of EZGUI button, and what is the reason to change the state? The reason deter$$anonymous$$es how you approach this problem.

avatar image samz · Apr 05, 2013 at 05:07 AM 0
Share

normal ezgui UIbutton.

i have an action button (ezgui UIbutton) for the player to press and attack (touch screen).

currently i have created an inventory of weapons which are made from UIButtons. When the user clicks these buttons i want the action button to change to the selected weapon.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by robertbu · Apr 05, 2013 at 06:44 AM

To implement what you describe, I'd use a State Toggle Button. This type of button allows you to define any number of states, and to set the graphic for each state. For what you describe, you would only need two states. After attaching the State Toggle Button component, select it in the hierarchy and open the UI Control Editor from Unity's Windows menu. You can drag and drop your two states into the editor. The second state will use your weapon graphic. This control will now toggle between the two states when pressed. If necessary, you can prevent the button from returning to its original state with a bit more work.

Comment
Add comment · Show 16 · 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 samz · Apr 05, 2013 at 09:10 AM 0
Share

Will this work if I had many weapons to choose from but only being allowex to equip one at a time?

avatar image robertbu · Apr 05, 2013 at 09:24 AM 1
Share

You can do whatever you want. Think of all the states as frames in an animation. Each state represents one frame. By default the states are walked in order wrapping at the end. But with a bit of code you can define any order you want.

Using State Toggle Buttons or Packed Sprites I often will define a generic game object with a large number of frames/states. Then in code I define the actual state. Think of a universal playing care capable of displaying any card in the deck. When I assign the value of that card in code, the card will display the correct value.

avatar image robertbu · Apr 06, 2013 at 06:17 AM 1
Share

Often I find my answers to EZGUI questions by searching on Above and Beyond's Forum (the maker of EZGUI). You can find the forum here:

http://forum.anbsoft.com

As for your question, there are a number of different ways to manage the state of toggle buttons. One way is to subclass the button:

 using UnityEngine;
 using System.Collections;
 
 public class $$anonymous$$yButton : UIStateToggleBtn {
 
     public override void  SetState (int index) {
     }
     
     public void $$anonymous$$ySetState(int index) {
         base.SetState (index);    
     }
 
 }

Note this script is derived from UIStateToggleBtn and is attached ins$$anonymous$$d of the State Toggle Button script. It stubs out SetState() and provides a method ($$anonymous$$ySetState()). You now have total control (and total responsibility) for setting the visual state.

A more usual method of managing the state would to add or replace the value change delegate. See the SetValueChangedDelegate() and AddValueChangeDelegate() in the EZGUI documentation.

I'm going to be offline for the next 5 days.

avatar image robertbu · Apr 11, 2013 at 04:34 AM 1
Share

You are to take my code, make it a script, and attach it to the object that needs to have it state managed. Note this script replaces UIStateToggleBtn. After the script is attached, you will use the UIControlEditor to set all the states and images. Since you are changing the state of the button from another game object you will need to create a variable in the script attached to the other game object:

 $$anonymous$$yButton mybutton;

Then you will need to initialize this variable either through dragging and dropping or by using GameObject.Find() and GetComponent(). Then when you want to use it:

 mybutton.$$anonymous$$ySetState(3);
avatar image robertbu · Apr 13, 2013 at 01:03 PM 1
Share

I'm traveling and will not have access to a computer with Unity for another week.

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

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

Assigning UV coords, from texture atlas. Losing texture uv accuracy at distance. 0 Answers

How to get access to the texture generated by built-in Sprite Packer? 2 Answers

It is possible to use texture atlases like button? 1 Answer

Is there a behind the scenes texture atlas? 2 Answers

Two Texture Atlas in the same model/Object 0 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