using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Swing : MonoBehaviour
{
private bool turnRight;
private bool turnLeft;
private float turnDegree=0;
void Start()
{
if (this.transform.localRotation.z==0)
{
turnRight = true;
turnLeft = false;
}
}
// Update is called once per frame
void Update()
{
Right();
Left();
}
/// <summary>
/// 向右摇摆
/// </summary>
private void Right()
{
if (turnRight == true)
{
if (turnDegree<2.0f)
{
turnDegree += Time.deltaTime;
this.transform.localEulerAngles =new Vector3 (0,0,turnDegree);
}
else
{
turnRight = false;
turnLeft = true;
}
}
}
private void Left()
{
if (turnLeft == true)
{
if (turnDegree>-2.0f)
{
turnDegree -= Time.deltaTime;
this.transform.localEulerAngles = new Vector3(0, 0, turnDegree);
}
else
{
turnRight = true;
turnLeft = false;
}
}
}
}
unity物体左右摇摆(旋转)
最新推荐文章于 2024-01-19 23:58:52 发布