Unity 鼠标点击左右移动,人物跟随旋转

1

上代码:

using UnityEngine;
using System.Collections;

public class Test : MonoBehaviour {

    private Vector3 startPosition;      //鼠标按钮的坐标点
    private float x;
    public bool isDown;                 //表示鼠标是否按下
    

    public void OnMouseDown() 
    {
        isDown = true;
        startPosition = Input.mousePosition;
    }

    public void OnMouseUp()
    {
        isDown = false;
    }


    public void Update() 
    {
        if(isDown)
        {
            x = Input.mousePosition.x - startPosition.x;
            this.transform.Rotate(new Vector3(0, -x, 0));           //开始旋转
            startPosition = Input.mousePosition;                    //重新记录鼠标的位置
        }
    }

}
posted @ 2015-01-28 01:23  盘子脸  阅读(2246)  评论(0编辑  收藏  举报