您好我正在使用C#在Unity中制作游戏,我想在按键机制上实现传送,但我遇到了一些代码问题
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Teleport: MonoBehaviour
{
private Transform player;
void Awake()
{
//Find the player object and set it
player = GameObject.FindGameObjectWithTag("Player").transform;
}
void Update()
{
// Checks if you click the space bar and gets you to -1, 0, 0
if (Input.GetKeyDown(KeyCode.Space)
transform.position = new Vector3 (-1, 0, 0);
}
}
如果你能告诉我什么是错的,或者甚至改进机制并以任何方式使它变得更好,我将不胜感激。
答案 0 :(得分:3)
你在这里缺少if (Input.GetKeyDown(KeyCode.Space)
player.position = transform.position = new Vector3 (-1, 0, 0);
:
if (Input.GetKeyDown(KeyCode.Space))
player.position = transform.position = new Vector3 (-1, 0, 0);
应该是:
case None => HttpResponse(StatusCodes.NotFound)
答案 1 :(得分:1)
您错过了一个近距离)
:
以下是检查变量是否为真的方法。
if(somthing)
以下是检查函数是否为真的方法。
if(GetKeyDown())
GetKeyDown函数:
boo GetKeyDown()
{
return ...;
}
private Transform player;
void Awake()
{
//Find the player object and set it
player = GameObject.FindGameObjectWithTag("Player").transform;
}
void Update()
{
// Checks if you click the space bar and gets you to -1, 0, 0
if (Input.GetKeyDown(KeyCode.Space))
transform.position = new Vector3(-1, 0, 0);
}