首页 > 编程语言 > 详细

Unity 物体围绕圆周运动

时间:2015-02-17 12:51:08      阅读:379      评论:0      收藏:0      [点我收藏+]

用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;
    }
}

 

Unity 物体围绕圆周运动

原文:http://www.cnblogs.com/vitah/p/4295119.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!