007-實現Unity3d中觸摸屏幕控制物體的移動 代碼實現

1.實現Unity3d中觸摸屏幕控制物體的移動 代碼實現

using UnityEngine;

using System.Collections;

public class haha : MonoBehaviour {
    public float speed = 0.01F;
    void Update()
    {
        if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved)
        {
            Vector3 touchDeltaPosition = Input.GetTouch(0).deltaPosition;
            transform.Translate(-touchDeltaPosition.x * speed, touchDeltaPosition.y * speed, 0);
        }
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章