有个需求是做一个圆环,圆环前有个起始点跟随圆环移动。圆环很简单,把图片类型设置为Filled 360度的,方向为Right,做个Dotween动画,圆环就可以动起来了。如图圆环设置
圆环上的起始点做法。
给定一个圆长度,速度,中心点就可以旋转了。上代码:
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中使用C#脚本实现动态创建并旋转的圆环效果,以及如何在圆环上放置一个跟随圆环旋转的起始点。通过设定圆环长度、旋转速度和中心点,可以精确控制起始点的移动路径。

3843

被折叠的 条评论
为什么被折叠?



