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 /
  • Help Room /
This question was closed Mar 19, 2016 at 11:55 AM by Osvaldon for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Osvaldon · Mar 18, 2016 at 10:28 AM · c#spriteupdate

Code doesn't work inside void Update()

 void Update()
 {
     if (Input.GetMouseButton(0))
     {
             Debug.Log("Test");
             if (gameObject.name == "Decrease")
             {
                 Debug.Log("Test1");
                 bar = GameObject.Find("Bar");
                 bar.transform.localScale += new Vector3(-0.01875F, 0, 0);
             }
             else if (gameObject.name == "Increase")
             {
                 Debug.Log("Test2");
                 bar = GameObject.Find("Bar");
                 bar.transform.localScale += new Vector3(0.01875F, 0, 0);
             }
      }
 }

The code works fine under OnMouseDown, but when I put it under Update, the scale is increased once no matter where on screen I click and nothing else seems to work anymore except for the test messages. And for some reason I get 8 messages every frame for Test message (1 for other messages), though I think there should be only 1 per frame.

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 Guhanesh · Mar 18, 2016 at 11:13 AM 0
Share

tried this code works perfectly for me.no problem with this code.

avatar image Osvaldon · Mar 18, 2016 at 11:59 AM 0
Share

I created a new project just in case and put this code there, I get the test messages, but the scale isn't changing. I get 3x more Test messages than Test1 or Test2. I don't get it... :(

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by Osvaldon · Mar 19, 2016 at 11:54 AM

Okay, it just hit me that void Update() doesn't give me a gameObject, so the fix was replacing gameObject with a new GameObject variable clickedObject and then getting it with OnMouseDown.

 private GameObject clickedObject;

 void OnMouseDown()
 {
     clickedObject = gameObject;
 }

 void OnMouseUp()
 {
     clickedObject = null;
 }
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

Follow this Question

Answers Answers and Comments

130 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 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

Need help with Async 0 Answers

why OnTriggerEnter is not work if with void Update 2 Answers

UI image component problems with Character Creation.... 0 Answers

No input after scene load 1 Answer

How can i put down a sprite on collision? 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