【发布时间】:2020-08-06 13:37:56
【问题描述】:
我是 c# 和 unity 的新手,我正在尝试制作 3d 游戏。这段代码应该让剑来回移动,当我按下按钮时,unity会承认它,但剑不会移动。有谁知道它为什么这样做?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class slash : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
bool slas = false;
if (Input.GetKeyDown(KeyCode.DownArrow))
{
slas = true;
}
if (slas = true)
{
transform.Rotate(0, 30, 0);
transform.Rotate(0,-30,0);
}
}
}
【问题讨论】:
-
您可能想要
if (slas == true),因为即使密钥未按下,您现在所拥有的始终是正确的。如果你想真正看到随着时间的推移的旋转,你需要做更多的工作。如果您在此处搜索,您可以找到有关以各种方式执行此操作的信息。