• 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 hema · Mar 17, 2014 at 12:50 PM · mouseclickhitcounter

Stop counter on the number dispalyed

Hi All,

I have small dot and a number on the screen. User has to hold the left mouse button on the dot such that one more counter starting from 0 should reach the number shown on the screen.

i have done this but when i release the mouse button it is difficult for me to get the exact number displayed. Please help me to optimize my code such that it will be easier to get the counter value.

Below is my code:

 Ray ray_=Camera.main.ScreenPointToRay(Input.mousePosition);
 if(Physics.Raycast(ray_.origin,ray_.direction*10,out m_hit)) 
 {
   if(m_hit.collider.gameObject.name=="Dot")
   {
     if(Input.GetMouseButton(0))
     {
       m_hit.collider.gameObject.transform.localScale+= new Vector3(0.01f,0.01f,0.01f);
       m_ForceReq++;
     }
   }
 }

Thanks in advance.

Comment
Add comment · Show 7
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 MousePods · Mar 17, 2014 at 01:09 PM 0
Share

Wouldn't it be easier to just have a script on the dot and use On$$anonymous$$ouseOver and inside that the GetButton? $$anonymous$$aybe this would help with the accuracy, idunno :/

avatar image Berenger · Mar 17, 2014 at 01:13 PM 0
Share

The player has to follow the dot with the mouse as it move around, is that it ? And you'd like to get the player's score (the timer) at the end. Could you show us how this timer is displayed, particulary where you get the string from ?

avatar image hema · Mar 17, 2014 at 01:27 PM 0
Share

No. the dot is stationary. Number on Screen : 75 Number required : 0 When the player holds the mouse button on the dot the number in the required field should increase and when it reaches 75 player has to release the mouse button.

Thanks for your replies.

@TobiasP will try your idea and let you know.

avatar image hema · Mar 18, 2014 at 09:36 AM 0
Share

@TobiasP i have tried your idea, but getting the same result.

avatar image CodeElemental · Mar 18, 2014 at 10:05 AM 0
Share

Why not update the time the user is holding on to the dot in update(). Something like :

 // This script is attached to the dot object
 
 private userHoldingDot = false; // whether the user has clicked while hovering over the dot
 private float timeHolding = 0f; // time the user has held over the dot.
 
 
 void Update()
 {
   if (Input.Get$$anonymous$$ouseButton(0) && userHoldingDot)
   {
     timeHolding += Time.deltaTime;
   }
 }
 
 void On$$anonymous$$ouseDown()
 {
  // when mouse entered and clicked
   userHoldingDot = true;
 }
 
 void On$$anonymous$$ouseExit()
 {
  // reset values when mouse leaves the dot, regardles of holding button
   userHoldingDot = false;
   timeHolding = 0f;
 }
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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

22 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

Related Questions

Having a problem with maintaining a spawn of 10 objects on my screen. 1 Answer

Timer Runtime Problem 2 Answers

Can anyone help ?? Timer and gui 0 Answers

pickup counter and timer help 0 Answers

How can I get an accurate gameObject count within a frame? 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