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 /
avatar image
0
Question by Mokhan94 · Oct 23, 2015 at 02:59 AM · inputtouchfunctioneventsystemevent triggering

Calling a function through EventTrigger does not loop.

Hello, I am calling a function through the new Unity UI system but it is not looping my function. I have attached my game object to the event trigger and the function I am calling is "TurnLeft". I am using the On Pointer Down event so it should play continuously.

Here is the function as well. I am trying to make my character rotate using the new UI system. Please help, I can't seem to find the solution.

 function TurnLeft(){
  transform.Rotate(Vector3(0,-1,0)*turnSpeed* Time.deltaTime);
  
  }





Comment
Add comment
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

1 Reply

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

Answer by seth_slax · Oct 23, 2015 at 04:48 AM

OnPointerDown is essentially the same as GetKeyDown, in that it only triggers when the key is initially pressed. To loop this, I'd suggest having the OnPointerDown switch on a boolean. Something along these lines:

 var turn : boolean;
 
 function Update(){
        if(turn){
               TurnLeft();
        }
 }
 
 function Turn(which : boolean){
        turn = which;
 }
 
 function TurnLeft(){
   transform.Rotate(Vector3(0,-1,0)*turnSpeed* Time.deltaTime);
   
   }

And then have your OnPointerDown call the Turn() function, specifying if you want it on or not.

Comment
Add comment · Show 3 · 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 Mokhan94 · Oct 23, 2015 at 08:51 AM 0
Share

Can I use the turn variable to turn right as well or would I have to create another variable to turn right? Thanks. Ie. if turn = left { TurnLeft () }

avatar image seth_slax Mokhan94 · Oct 23, 2015 at 09:03 AM 0
Share

Depends, really. If you want it to always turn left or right, you could keep to one boolean, or have two to control them independantly. Booleans only have a true or false state. Alternatively, you could use an int . For example 0 = no movement, 1 = left and 2 = right, or do something similar with a string. Hope this helps!

avatar image Mokhan94 · Oct 23, 2015 at 02:17 PM 1
Share

Great! Thanks for all the help. $$anonymous$$uch appreciated.

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

35 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

Related Questions

Massive lag spike on first Input.GetTouch with nothing on scene but one script (Android) 2 Answers

Mouse or Touch events independent of framerate 0 Answers

Sprite/gameObject touch or click event 0 Answers

Detect if mouse has clicked on a UI element? 0 Answers

OnDrag is moving all colliders on Touch? (Not on Standalone) 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