Last active
December 16, 2015 19:50
-
-
Save s2kw/5487841 to your computer and use it in GitHub Desktop.
Touch for ios.
Click for Editor.
this code is compatible.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class TouchOrClick : MonoBehaviour | |
{ | |
public float touchSpeed = 1.0f; | |
// Use this for initialization | |
void Start () { | |
Debug.Log("touch start"); | |
} | |
// Update is called once per frame | |
void Update () { | |
#if UNITY_EDITOR | |
if(Input.GetButtonDown("Fire1")){ | |
Vector3 clickDeltaPosition = Input.mousePosition; | |
Ray ray = Camera.main.ScreenPointToRay(clickDeltaPosition); | |
if(Physics.Raycast(ray)){ | |
transform.Rotate( clickDeltaPosition.y * touchSpeed * 10f, | |
clickDeltaPosition.x * touchSpeed * 10f, | |
0f, | |
Space.World); | |
Debug.Log("Clicked"); | |
} | |
} | |
#elif UNITY_IPHONE | |
// Get Touch Count. | |
int fingerCount = 0; | |
foreach ( var touch in Input.touches ) | |
{ | |
if( touch.phase == TouchPhase.Ended )return; | |
if( touch.phase == TouchPhase.Canceled )return; | |
fingerCount++; | |
} | |
if(Input.touchCount <= 0) return; | |
//change to Behavior by phase. | |
switch(Input.GetTouch(0).phase) | |
{ | |
case TouchPhase.Began: | |
Debug.Log("Begin"); | |
break; | |
case TouchPhase.Moved: | |
Debug.Log("Moved"); | |
Vector2 touchDeltaPosition = Input.GetTouch(0).deltaPosition; | |
transform.Rotate( touchDeltaPosition.y * touchSpeed * 10f, | |
touchDeltaPosition.x * touchSpeed * 10f, | |
0f, | |
Space.World); | |
Debug.Log("Touched"); | |
break; | |
case TouchPhase.Ended: | |
Debug.Log("Ended"); | |
break; | |
} | |
#endif | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment