OvertakingLegend/Assets/Property/Model/art_overtakongmaster/Prefab/fx_0908/FloatMove.cs

24 lines
732 B
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using UnityEngine;
using System.Collections;
public class FloatMove : MonoBehaviour
{
public float radian = 0; // 弧度
public float perRadian = 0.03f; // 每次变化的弧度 上下浮动
public float radius = 0.1f; // 半径
Vector3 oldPos; // 开始时候的位置坐标
// Use this for initialization
void Start()
{
oldPos = transform.position; // 将最初的位置保存到oldPos
}
// Update is called once per frame
void Update()
{
radian += perRadian; // 弧度每次加0.03
float dy = Mathf.Sin(radian) * radius; // dy定义的是针对y轴的变量也可以使用sin找到一个适合的值就可以
transform.position = oldPos + new Vector3(0, dy, 0);
}
}