【发布时间】:2019-06-05 15:59:58
【问题描述】:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Rotate : MonoBehaviour
{
enum Axistorotate { Back, Down, Forward, Left, Right, Up, Zero};
public float angle;
public float speed;
public Vector3 axis;
private bool stopRotation = true;
private Axistorotate myAxis;
// Start is called before the first frame update
void Start()
{
myAxis = Axistorotate.Left;
StartCoroutine(RotateObject());
}
// Update is called once per frame
void Update()
{
if(Input.GetKeyDown(KeyCode.S))
{
stopRotation = false;
}
if (Input.GetKeyDown(KeyCode.C))
{
stopRotation = true;
StartCoroutine(RotateObject());
}
}
IEnumerator RotateObject()
{
while (stopRotation == true)
{
transform.Rotate(Axistorotate.Left, angle);
yield return new WaitForSeconds(speed);
}
}
}
在线:
transform.Rotate(Axistorotate.Left, angle);
我想使用枚举或制作一些我可以在 Vector3.Left 或 Vector3.Right 之间进行选择的东西....以及所有轴,比如枚举。
这个想法是能够在这一行而不是多行上使用简而言之枚举或vector3轴。
【问题讨论】:
-
所以你想把 Axistorotate.Left 转换成 Vector3.Left?
-
Ty 在枚举上使用 switch 语句来设置轴。