我如何使用Mathf.PingPong在最大和最小之间缩放和旋转对象?

问题描述 投票:0回答:1
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RotateAndScale : MonoBehaviour
{
    public Transform target; // Target to scale
    public Vector3 minScale; // Minimum scale value
    public Vector3 maxScale; // Maximum scale value
    public Vector3 maxRotate;
    public Vector3 minRotate;
    public float speed;

    private float t = 0.0f;

    void Update()
    {
        //if (Input.GetKey(KeyCode.C))
        //{
        t += speed * Time.deltaTime;
            target.localScale = Vector3.Lerp(target.localScale, maxScale, t);
            target.localRotation = Quaternion.Lerp(target.localRotation,
                Quaternion.Euler(maxRotate.x, maxRotate.y, maxRotate.z), t);
       // }
    }
}

这将缩放并旋转对象至最大一次。但我希望它达到最大,然后回到最小,然后回到最大和最小不间断。

然后,我想使用一个键,例如C,当在C上按下一次时,它将最大化,而在C上再次按下,它将回到最小。

但是首先我不确定如何使用乒乓不停,然后如何使用钥匙?

c# unity3d
1个回答
0
投票

Mathf.PingPong使用时间输入,然后在Mathf.PingPong和给定的最大参数之间来回移动。

在您的情况下,您想使用速度值作为时间输入的乘数升至0

喜欢这个

1
© www.soinside.com 2019 - 2024. All rights reserved.