本案例素材和教程都来自Siki学院,十分感谢教程中的老师
本文仅作学习笔记分享交流,不作任何商业用途
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Pencil : MonoBehaviour
{
//摆动速度
public float pencilSpeed;
//摆动频率
public float pencilSquency;
//初始角度
private float StartZ;
// Start is called before the first frame update
void Start()
{
StartZ = transform.localEulerAngles.z;
}
// Update is called once per frame
void Update()
{
transform.localEulerAngles = new Vector3(0, 0, StartZ+
Mathf.Sin(Time.time*pencilSquency) *pencilSpeed);
}
}