Created
May 1, 2013 06:14
-
-
Save s2kw/5493995 to your computer and use it in GitHub Desktop.
Editors script updated from previous post.
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 Touchable3DObject : MonoBehaviour | |
{ | |
public float maxSpeed = 100f; | |
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.GetButton("Fire1")){ | |
Vector3 clickDeltaPosition = Input.mousePosition; | |
Ray ray = Camera.main.ScreenPointToRay(clickDeltaPosition); | |
RaycastHit hit; | |
if(Physics.Raycast(ray, out hit)){ | |
if( hit.collider.gameObject != gameObject ) return; | |
transform.Rotate( | |
(clickDeltaPosition.y * touchSpeed < maxSpeed) ? clickDeltaPosition.y * touchSpeed : maxSpeed, | |
(clickDeltaPosition.x * touchSpeed < maxSpeed) ? clickDeltaPosition.x * touchSpeed : maxSpeed, | |
(clickDeltaPosition.z * touchSpeed < maxSpeed) ? clickDeltaPosition.z * touchSpeed : maxSpeed, | |
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