Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class TouchSpin: MonoBehaviour {
- public bool touched;
- public float touchBegin;
- public float touchEnd;
- public float touchDir;
- public float clickBegin;
- public float clickEnd;
- public float clickDir;
- public float spin;
- // Use this for initialization
- void Start ()
- {
- touched = false;
- }
- // Update is called once per frame
- void Update ()
- {
- transform.Rotate(0, 0, spin);
- if(spin > .1f && !touched)
- {
- spin-=.05f;
- }
- else if(spin < 0 && !touched)
- {
- spin+=.05f;
- }
- else if(!touched)
- {
- spin = 0;
- }
- if(Input.GetButtonDown("Fire1"))
- {
- clickBegin = Input.mousePosition.x;
- touched = true;
- }
- if(Input.GetButton ("Fire1") && touched)
- {
- clickEnd = Input.mousePosition.x;
- clickDir = clickEnd - clickBegin;
- clickBegin = clickEnd;
- }
- if(Input.GetButtonUp("Fire1"))
- touched = false;
- if(clickDir > 0)
- {
- //rigidbody.AddTorque(new Vector3(0,0, 1) * clickDir);
- spin = -clickDir/10;
- }
- else if(clickDir < 0)
- {
- //rigidbody.AddTorque(new Vector3(0,0, 1) * clickDir);
- spin = -clickDir/10;
- }
- clickDir = 0;
- foreach (Touch touch in Input.touches)
- {
- if(touch.phase == TouchPhase.Began)
- {
- touchBegin = touch.position.x;
- touched = true;
- }
- if(touch.phase == TouchPhase.Moved)
- {
- touchEnd = touch.position.x;
- touchDir = touchEnd - touchBegin;
- touchBegin = touchEnd;
- if(touchDir > 0)
- {
- //gameObject.rigidbody.AddTorque(new Vector3(1,0,0) * touchDir);
- spin = touchDir/10;
- }
- else if(touchDir < 0)
- {
- //gameObject.rigidbody.AddTorque(new Vector3(1,00) * touchDir);
- spin = touchDir/10;
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment