(Unity)オブジェクトを指定角度まで滑らかに回転させる方法(Rotate/RotateTowards)

<動き>

・一定の高さまで上昇した後に、ゆっくり角度を変更させる。


(スクリプトその1:Rotateで実装)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MoveRotate1 : MonoBehaviour
{
    private Vector3 pos;
    private Quaternion rot;

    void Update()
    {
        pos = transform.position;
        rot = transform.rotation;

        print(rot.z);

        if (pos.y < 5.1f)
        {
            transform.Translate(Vector3.up * Time.deltaTime);
        }
        if (pos.y > 5.0f)
        {
            Invoke("BRotate", 0.5f);
        }
    }

    void BRotate()
    {
        if (rot.z > -0.22f)
        {
            transform.Rotate(new Vector3(0, 0, -10) * Time.deltaTime);
        }
    }
}

(スクリプトその2:RotateTowardsで実装)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MoveRotate2 : MonoBehaviour
{
    private Vector3 pos;
    private Quaternion rot;

    void Update()
    {
        pos = transform.position;
        rot = transform.rotation;

        print(rot.z);

        if (pos.y < 5.1f)
        {
            transform.Translate(Vector3.up * Time.deltaTime);
        }
        if (pos.y > 5.0f)
        {
            Invoke("BRotate", 0.5f);
        }
    }

    void BRotate()
    {
        if (rot.z > -0.22f)
        {
            transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.Euler(0, 0, -25), 0.3f);
        }
    }
}