Files
Net.Like.Xue.Tokyo/Packages-Local/Com.Project.B.Unity/World/Platform/WorldPlatformController.cs
2025-06-24 23:49:13 +08:00

35 lines
1010 B
C#

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Net.Project.B.World.Platform
{
public class WorldPlatformController : MonoBehaviour
{
[SerializeField] private Vector3 rot = Vector3.up;
[SerializeField] private Vector3 move = Vector3.up;
public float moveSpeed = 2f; // 上下移动的速度
public float moveHeight = 1f; // 上下移动的高度
public float rotateSpeed = 50f; // 旋转速度(度/秒)
private Vector3 startPosition;
void Start()
{
startPosition = transform.localPosition; // 记录初始位置
}
void Update()
{
// 上下移动(使用正弦波模拟平滑运动)
var pos = startPosition + move * Mathf.Sin(Time.time * moveSpeed);
transform.localPosition = pos;
// 旋转
transform.Rotate(rot * (rotateSpeed * Time.deltaTime));
}
}
}