开始学习unity3d游戏制作。
using UnityEngine;
public class PlayerController : MonoBehaviour
{
/// <summary>
/// The current touch positon.
/// </summary>
private Vector3 cTP = new Vector3 ();
/// <summary>
/// The start touch position.
/// </summary>
private Vector3 sTP = new Vector3 ();
/// <summary>
/// The start transform position.
/// </summary>
private Vector3 sTfP = new Vector3 ();
/// <summary>
/// Update is called once per frame
/// </summary>
private void Update ()
{
if (Input.touchCount == 1) {
//current Touch
Touch cT = Input.touches [0];
if (cT.phase == TouchPhase.Moved) {
cTP = Camera.main.ScreenToWorldPoint (cT.position);
transform.position = new Vector3 (
cTP.x - sTP.x + sTfP.x,
cTP.y - sTP.y + sTfP.y,
sTfP.z);
} else if (cT.phase == TouchPhase.Began) {
sTP = Camera.main.ScreenToWorldPoint (cT.position);
sTfP = transform.position;
}
}
}
}
示例代码:http://download.csdn.net/detail/wuyt2008/9071187