创建一个cube和plane,编写代码,选择旋转轴以及旋转速度,使cube绕轴旋转。
代码如下
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using UnityEngine;
public class trans : MonoBehaviour
{
public enum mou
{
MouseX=0,
MouseY=1,
MouseZ=2,
}
public mou a = mou.MouseX;
public float speed = 3f;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (a ==mou.MouseX) {
transform.Translate(speed, 0, 0);
}
if (a == mou.MouseZ)
{
transform.Translate(0, speed, 0);
}
else
{
transform.Translate(0, 0, speed);
}
}
}