• 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 NewBeeLiu · Nov 29, 2015 at 08:14 PM · c#triggeranimationstouch controls

touch to activate animation

Hey guys,

I have a touch screen rotation script that works on rotating a object √

Now I want to keep track of the number of times I have turned it so that on the 3rd turn I can trigger a boolean to start an animation...

Here is the touch screen script below:

 using UnityEngine;
 using System.Collections;
 
 public class rotateTest : MonoBehaviour {
 
     public float speed;
     public float xDeg,yDeg,lerpSpeed,friction ;
     Quaternion fromRotation, toRotation;
 
 // to keep track of initial Position ?:
        public  Vector3 initialPos;
 //Number of orations..?
        public int myNumberRotate;
 
 
 void OnMouseDown() 
 {
 //Pseudo Code:
 //set initialPos;
 //set myNumberRotate= 0;
 }
 void OnMouseUp()
 {
 //Pseudo Code:
 // how to keep track of rotations around the Y Axis > 3...?
 }
 
 //TOUCH CODE BELOW WORKS FINE:
 
 voidUpdate () 
     { 
     if(Input.GetTouch(0).phase== TouchPhase.Moved)
     RotateTransform(Input.GetTouch(0).deltaPosition.x, Input.GetTouch(0).deltaPosition.y); 
     elseRotateTransform(0f, 0f); 
     
     }
     
     voidRotateTransform( floatxNum, floatyNum) {
     xDeg -= xNum*speed*friction;
     yDeg -= 0;
     //yDeg -= yNum*speed*friction; 
     fromRotation = transform.rotation;
     toRotation = Quaternion.Euler(yDeg,xDeg,0);
     transform.rotation = Quaternion.Lerp(fromRotation,toRotation,1 ); 
     }
 
 }
 

Comment
Add comment · Show 1
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 Bentoon · Dec 03, 2015 at 07:39 PM 0
Share

interesting Question!

*bump"

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

36 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

Related Questions

Enabling particle system with trigger 1 Answer

How to get the Collider other element Rigidbody? 0 Answers

OnTriggerExit2D doesn't work when one of gameObject setActive false. 0 Answers

How can I make a song play when an NPC gets within a certain range of the player? 2 Answers

Problem in Destroy GameObject on OnTriggerEnter2D 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges