Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
This question was closed Jun 18, 2017 at 01:30 PM by G3R1 for the following reason:

Other

avatar image
0
Question by G3R1 · Jun 18, 2017 at 11:18 AM · buttonspriteswap

Button Sprite Swap ?

Hi,

Is there a way how to control the sprite states of a button when it is clicked ? I mean i have 10 buttons in total and if one of these buttons is clicked i want to set its state to pressed and others to disabled. How can i do this ? Is there a way to assign these sprites to each state of Sprite Swap Transition of the buttons and then decide which one of them should be in a pressed state and others in disabled state through script ?

Also, I don't want to assign all the sprites manually to my script because there are 10 buttons and each of them has 3 different states so in total it would be 30 sprites to assign in the inspector and I want to avoid that. It would be better if these sprites could be assigned directly to the transition mode of the buttons and then in my script i would set the sprite state of each button depending on the condition that i want to have.

Here is the code that i am using to set the button of the selected item to pressed state:

 public Button[] shopItemButtons;
 
 void Start()
     {
         for (int i = 0; i < shopItemButtons.Length; i++)
         {
             shopItemButtons[selectedItem].spriteState = shopItemButtons[selectedItem].spriteState.pressedSprite;
         }
     }

If anyone has an idea please share it. Thank you, Gerald.

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 G3R1 · Jun 18, 2017 at 11:22 AM 0
Share

Also, this is the error i get when i use this code:

Cannot implicitly convert type UnityEngine.Sprite' to UnityEngine.UI.SpriteState'

1 Reply

  • Sort: 
avatar image
0

Answer by SnStarr · Jun 18, 2017 at 01:00 PM

Sure. Have the event system handle it. Unity's built in event system can tell which element its not currently hovering over then if the buttons that is not being hovered over by the mouse can be set to disabled. Hence swapping the sprite. If you set the sprite on the button in inspector.

Comment
Add comment · Show 2 · 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 G3R1 · Jun 18, 2017 at 01:29 PM 0
Share

Hi,

i just solved it differently changing the image sprite of the button through script. Thank's for your reply.

avatar image logicandchaos · Feb 28, 2018 at 06:17 PM 0
Share

Hey I am trying to do the same thing as OP, but when I set button.enabled=false, it doesn't change the sprite to disabled, I have the sprites setup in unity editor

Follow this Question

Answers Answers and Comments

94 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 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 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 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 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 avatar image avatar image avatar image avatar image

Related Questions

GUI Button, Sprite Swap on Timer (Flashing) 0 Answers

Image Sprite doesn't change with Button Onclick 0 Answers

(Unity 4.6) Button animations 1 Answer

How to add a Sprite Rollover Image using a Button Array 0 Answers

2D sprite ordering problem 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