Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 Kuwmii · Jul 19, 2015 at 06:18 AM · 2dbuttondisablekeypress

Disable Sprite when keypress (Working Script, just need disble)

Hello guys!

I made this script and you are free to use it. When you press ,1,2,3 a sprite will display. What I need is when you press ,1,2,3 a sprite will disable and enable the other one. So it's like when you press 1, 1 will disable and enable 2 rather then just display sprites all in all when you press the buttons. Hope you can help! thanks. Here is the script.

 var Weapon1: Sprite;
 var Weapon2: Sprite;
 var Weapon3: Sprite;
 var Weapon4: Sprite;
 
 var sprite : SpriteRenderer;
 
 function Start ()
 {
     sprite = GetComponent(SpriteRenderer);
 }
 
 function Update ()
 {
     if(Input.GetKey(KeyCode.Alpha2))
     {
         sprite.sprite = Weapon1;
     }
 
     if(Input.GetKey(KeyCode.Alpha1))
     {
         sprite.sprite = Weapon2;
     }
     
         if(Input.GetKey(KeyCode.Alpha3))
     {
         sprite.sprite = Weapon3;
     }
     
             if(Input.GetKey(KeyCode.BackQuote))
     {
         sprite.sprite = Weapon4;
     }
 }
Comment
Add comment · Show 6
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 Priyanshu · Jul 19, 2015 at 07:09 AM 0
Share

your current script changes a single weapon Picture with button presses?

And you want to enable/disable different pictures at different location with button presses?

avatar image gorbit99 · Jul 19, 2015 at 07:19 AM 0
Share

$$anonymous$$aybe renderer.disable = true help you

avatar image Kuwmii · Jul 19, 2015 at 11:27 AM 0
Share

Thanks for your answers, yes at the moment the sprite that displays just displays and the others stay there too. So when you press 1, 2 will display but 1 will still display. I want to enable/disable each picture when you press the buttons. I tried Renderer.Disable = true however it's not actually working

avatar image Kuwmii · Jul 19, 2015 at 07:09 PM 0
Share

Thanks for your answers, Yes what I need is when you press 1 key for example a sprite will display, then when you press 2 key the 1 key sprite will disable and only enable the 2 sprite. At the moment each key you press will only display a sprite which is working, I just need something like Renderer.disable/enable for each sprite however can't get it to work .. argh.

avatar image Kuwmii · Aug 11, 2015 at 09:19 PM 0
Share

Already tried that, however it didn't work. Anyone have other solution? :)

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Disable diagonal movement on 2D character controller 1 Answer

Unity UI button does not detect click 2 Answers

How do I make a button press transition between phases properly? 0 Answers

Colored border of button with GUI skin 0 Answers

control button with keypad 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