美文网首页
unity 物体旋转与缩放

unity 物体旋转与缩放

作者: Albert_d37d | 来源:发表于2020-06-02 15:50 被阅读0次

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using HedgehogTeam.EasyTouch;

public class ModelController : MonoBehaviour

{

    float deltaX;

    float deltaY;

    private void Awake()

    {

        EasyTouch.On_PinchIn += OnPinchIn;

        EasyTouch.On_PinchOut += OnPinchOut;

    }

    private void OnDestroy()

    {

        EasyTouch.On_PinchIn -= OnPinchIn;

        EasyTouch.On_PinchOut -= OnPinchOut;

    }

    private void OnPinchIn(Gesture g)

    {

        if(transform.localScale.x > 1)

        {

            float temp = Time.deltaTime * g.deltaPinch;

            temp = transform.localScale.x - temp;

            temp = temp < 1 ? 1 : temp;

            transform.localScale = new Vector3(temp,temp,temp);

        }

    }

    private void OnPinchOut(Gesture g)

    {

        if(transform.localScale.x < 4)

        {

            float temp = Time.deltaTime * g.deltaPinch;

            temp = transform.localScale.x + temp;

            temp = temp > 4 ? 4 : temp;

            transform.localScale = new Vector3(temp, temp, temp);

        }

    }

    // Update is called once per frame

    void Update()

    {

        if (Input.GetMouseButton(0))

        {

            deltaY = -Input.GetAxisRaw("Mouse X") * 5f;

            deltaX = Input.GetAxisRaw("Mouse Y") * 5f;

        }

        else

        {

            deltaX *= 0.9f;

            deltaY *= 0.9f;

        }

        transform.Rotate(new Vector3(deltaX, deltaY, 0), Space.World);

    }

}

相关文章

网友评论

      本文标题:unity 物体旋转与缩放

      本文链接:https://www.haomeiwen.com/subject/mzwuzhtx.html