Unity 物體圍繞圓周運動


用Unity開發游戲中,經常會有搜尋的功能,這時候我們需要一個放大鏡的圖標在那圓周運動。寫了相關腳本直接掛載在要圓周運動的物體上即可:

using UnityEngine;
using System.Collections;

public class RoundAction : MonoBehaviour
{
    public float _radius_length;
    public float _angle_speed;

    private float temp_angle;

    private Vector3 _pos_new;

    public Vector3 _center_pos;

    public bool _round_its_center;

    // Use this for initialization
    void Start()
    {
        if (_round_its_center)
        {
            _center_pos = transform.localPosition;
        }
    }

    // Update is called once per frame
    void Update()
    {
        temp_angle += _angle_speed * Time.deltaTime; // 

        _pos_new.x = _center_pos.x + Mathf.Cos(temp_angle) * _radius_length;
        _pos_new.y = _center_pos.y + Mathf.Sin(temp_angle) * _radius_length;
        _pos_new.z = transform.localPosition.z;

        transform.localPosition = _pos_new;
    }
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM