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 /
avatar image
0
Question by Ki4Chan · Aug 12, 2017 at 06:25 AM · buttontouchpressed

speed increase only when button is pressed(touch).

I want to increase object's speed only when the button is pressed(touched), it should come back to normal speed when the button is not pressed(touched).

 transform.Translate(direction * Time.deltaTime * speed);

I tried

 public void SpeedUp(){
   speed * 10;
 }

and added this to button. Speed is increasing when button is pressed but not coming back to normal when button is left.

Comment
Add comment · Show 4
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 Ali-hatem · Aug 15, 2017 at 11:05 AM 0
Share

are you using unity ui button on click event or costume script ?

avatar image Ki4Chan Ali-hatem · Aug 16, 2017 at 10:33 AM 0
Share

yes, I am using unity UI OnClick event. I have added SpeedUp() function to the OnCLick event of button UI.

 public void SpeedUp()
 {
 speed = speed * 10;
 }

avatar image Ali-hatem Ki4Chan · Aug 16, 2017 at 10:37 AM 0
Share

i will answer!

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Ali-hatem · Aug 16, 2017 at 10:48 AM

  1. remove the on click and add event trigger component to the button

  2. in the event trigger add new event type and select PointerDown

  3. again add new event type and select PointerUp

  4. now you know the rest each event needs a public function one for pressing & other for releasing the same way you handle on click event.

Comment
Add comment · Show 4 · 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 Ki4Chan · Aug 16, 2017 at 10:51 AM 0
Share

okay let me try.

avatar image Ki4Chan · Aug 16, 2017 at 01:35 PM 0
Share

This works perfectly. Thanks.

avatar image Ali-hatem Ki4Chan · Aug 16, 2017 at 05:30 PM 0
Share

great good luck.

avatar image theprateektomar Ki4Chan · Sep 17, 2021 at 03:23 AM 0
Share

can you share your compete code ?

avatar image
0

Answer by unidad2pete · Aug 12, 2017 at 06:49 AM

 if(Input.GetKey(KeyCode.Space))
             {
                 speed = 10;
             } else
             {
                 speed = 1;
             }
Comment
Add comment · Show 6 · 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 Ki4Chan · Aug 12, 2017 at 06:54 AM 1
Share

That's for keyboard, how to do it for Android and iOS. I have used button UI..

avatar image omaimah Ki4Chan · Aug 15, 2017 at 10:15 AM 0
Share

Hi, I want to ask the same question when i'm using UI button@unidad2pete . did you know how to do it ? @$$anonymous$$i4Chan

avatar image Ki4Chan omaimah · Aug 16, 2017 at 09:10 AM 0
Share

still trying to figure it out. If you find something before me please let me know.

Show more comments
avatar image Zeusko · Aug 15, 2017 at 10:25 AM 0
Share

https://docs.unity3d.com/ScriptReference/UI.Button-onClick.html

avatar image Ki4Chan Zeusko · Aug 16, 2017 at 10:38 AM 0
Share

This is what I have tried, this works to increase the speed of that object but on leaving the button the speed is not co$$anonymous$$g back to normal.

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

104 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

Related Questions

time out between 2 touches android 1 Answer

Stop shooting when I press a gui button 1 Answer

If you help me, i make you 3d object 1 Answer

Touch Button animation 0 Answers

Touch button to load scene, instead of touching anywhere on screen 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