Unity3D中鼠标旋转物体

来源:互联网 发布:java模拟器安卓4.4.2版 编辑:程序博客网 时间:2024/04/25 18:33
using UnityEngine;
using System.Collections;
/*
 * 物体旋转的脚本
 * 物体左右旋转()
 */
public class RotateMouse : MonoBehaviour
{
    private bool isRotate;
    public float RotatedSpeed = 1000.0F;
    void Start()
    {
        isRotate = false;
    }


    // Update is called once per frame
    void Update()
    {


        if (Input.GetMouseButton(0))
        {
            float y = 0;


            y = Input.GetAxis("Mouse X") * RotatedSpeed * Time.deltaTime;
            if (isRotate)
            {
                gameObject.transform.Rotate(new Vector3(0, -y, 0));


            }


        }


    }
    void OnMouseDown()
    {
        isRotate = true;
        Debug.Log("collider");
    }
    void OnMouseUp()
    {
        isRotate = false;
        Debug.Log("Out of collider");
    }


}
0 0
原创粉丝点击