这里的脚本要实现的功能是在角色选择界面,
人物3D模型自动旋转,然后鼠标在角色身上向左拖拽,角色往左旋转;
向右拖拽,角色向右旋转,拖拽后角色旋转方向与退出拖拽时,
鼠标的移动方向一致。单击人物则停止旋转。
下面是脚本,这里不作过多解释:
using UnityEngine;
using System.Collections;
public class OnCharacterClick : MonoBehaviour {
Vector3 preMousePos,downPos;
float rotateDir=1;
bool dragging;
public float rotateSmoothing;
// Use this for initialization
void Start () {
InvokeRepeating("detectMousePos",0.1f,0.1f);
}
void detectMousePos()
{
preMousePos = Input.mousePosition;
}
// Update is called once per frame
void Update () {
if (!dragging)
{
transform.Rotate(transform.up,rotateDir*rotateSmoothing);
}
}
void OnMouseDrag()
{
dragging = true;
//当值小于0,说明鼠标向左拖,否则相反
float dragDeltaX=Input.mousePositio