PowenKo, Unity 3d b36, iphone input.

September 6, 2011   ·   0 Comments




 

 

switch ( Touches[ i ].phase )
                    {
                        case iPhoneTouchPhase.Began:
                            Debug.Log( "# Touch " + i + ", fid " + Touches[i].fingerId + ", Began" );
                            break;

                        case iPhoneTouchPhase.Moved:
                            Debug.Log( "# Touch " + i + ", fid " + Touches[ i ].fingerId + ", Moved" );
                            break;

                        case iPhoneTouchPhase.Stationary:
                            Debug.Log( "# Touch " + i + ", fid " + Touches[ i ].fingerId + ", Stationary" );
                            break;

                        case iPhoneTouchPhase.Canceled:
                            Debug.Log( "# Touch " + i + ", fid " + Touches[ i ].fingerId + ", Canceled" );
                            break;

                        case iPhoneTouchPhase.Ended:
                            Debug.Log( "# Touch " + i + ", fid " + Touches[ i ].fingerId + ", Ended" );
                            break;
                    }

 

c# version

using UnityEngine;
using System.Collections;

public class iphone_input : MonoBehaviour {

    private  string[] line=new string[5];

	private  GameObject[] thing=new GameObject[5];

	// Use this for initialization
	void Start () {

	}

	// Update is called once per frame
	void Update () {

		foreach (iPhoneTouch touch in iPhoneInput.touches){

	//		for(touch in iPhoneInput.touches){
			if(touch.phase == iPhoneTouchPhase.Moved || touch.phase == iPhoneTouchPhase.Began) {
				thing[touch.fingerId].transform.position = Camera.main.ScreenToWorldPoint(new Vector3 (touch.position.x, touch.position.y, 5));
			}
			if(touch.phase != iPhoneTouchPhase.Ended && touch.phase != iPhoneTouchPhase.Canceled) {
				line[touch.fingerId] = touch.fingerId + " (" + touch.phase +") "+ " " + touch.position.ToString() + "";
			} else {
				line[touch.fingerId] = "";
			}
		}
	}

	void OnGUI () {
	GUI.color =new  Color(0,0.9f,0);
	GUI.Label (new Rect (0, 0, 500, 20), "PowenKo.com");
	GUI.Label (new Rect (20, 35, 500, 20), line[0]);
	GUI.Label (new Rect (20, 50, 500, 20), line[1]);
	GUI.Label (new Rect (20, 65, 500, 20), line[2]);
	GUI.Label (new Rect (20, 80, 500, 20), line[3]);
	GUI.Label (new Rect (20, 95, 500, 20), line[4]);
	}
}

javascript version.


var thing = new GameObject[5];
var line = new String[5];

function Update () {

  	for(touch in iPhoneInput.touches){
		if(touch.phase == iPhoneTouchPhase.Moved || touch.phase == iPhoneTouchPhase.Began) {
			thing[touch.fingerId].transform.position = Camera.main.ScreenToWorldPoint(new Vector3 (touch.position.x, touch.position.y, 5));
		}
		if(touch.phase != iPhoneTouchPhase.Ended && touch.phase != iPhoneTouchPhase.Canceled) {
			line[touch.fingerId] = touch.fingerId + " (" + touch.phase +") "+ " " + touch.position.ToString() + "";
		} else {
			line[touch.fingerId] = "";
		}
	}

}

function OnGUI () {
	GUI.color = Color(0,0.9,0);
	GUI.Label (Rect (0, 0, 500, 20), "PowenKo.com");
	GUI.Label (Rect (20, 35, 500, 20), line[0]);
	GUI.Label (Rect (20, 50, 500, 20), line[1]);
	GUI.Label (Rect (20, 65, 500, 20), line[2]);
	GUI.Label (Rect (20, 80, 500, 20), line[3]);
	GUI.Label (Rect (20, 95, 500, 20), line[4]);
}

sample code:
b36_iphone_input

shareShare on FacebookShare on Google+Share on LinkedInEmail this to someonePrint this pageBuffer this pageDigg thisFlattr the authorShare on RedditPin on PinterestShare on StumbleUponShare on TumblrTweet about this on Twitter

By


Readers Comments (0)


You must be logged in to post a comment.

PowenKo’s Online Store

powenko_arduinoBook
Unity3D4

Amazon

adsbygoogle

Recent Posts

Categories

Amazon