From Unify Community Wiki
Revision as of 20:42, 16 April 2011 by Bunny83 (Talk | contribs)

Jump to: navigation, search

Author: Kiyaku


Sometimes, when i am working on an iPhone Application, the Client wants to try the game without using an iPhone. So i wrote a little script that converts some Mouse Functions into iPhoneInput function. You just have to add a few lines but can keep your original gameplay code.

Right now it can recognize touchCount 0 or 1, positions and returns "iPhoneTouchPhase Began, Moved, Ended".

Feel free to extend it!


Create a file named "iPhoneToMouse.cs" and add following code to it:

<csharp> using UnityEngine; using System.Collections;

public class iPhoneToMouse { public int touchCount { get { if(Input.GetMouseButton(0) || Input.GetMouseButton(1) || Input.GetMouseButtonUp(0) || Input.GetMouseButtonUp(1) ) return 1; else return 0; } }

public pos GetTouch(int ID) { pos tempPos = new pos();

tempPos.position = Input.mousePosition;

if(Input.GetMouseButtonDown(ID)) tempPos.phase = iPhoneTouchPhase.Began; else if(Input.GetMouseButton(ID)) tempPos.phase = iPhoneTouchPhase.Moved;

if(Input.GetMouseButtonUp(ID)) tempPos.phase = iPhoneTouchPhase.Ended;

return tempPos; }

public struct pos { public Vector2 position; public iPhoneTouchPhase phase; } }

public enum iPhoneTouchPhase { Moved, Ended, Began } </csharp>

Add following lines to your scripts which include iPhoneTouch commands:

<csharp> private iPhoneToMouse iPhoneInput;

void Start() { iPhoneInput = new iPhoneToMouse(); } </csharp>

That's it!

Personal tools