【发布时间】:2018-05-28 03:44:26
【问题描述】:
我正在使用 Unity 制作 2d 游戏。我有一个附有这个脚本的玩家精灵。左右键移动完美,但是当我尝试获取空格键时,它不起作用
using System.Collections;
using System.Collections.Generic;
using System;
using UnityEngine;
public class Player : MonoBehaviour {
public float moveSpeed;
public float jumpHeight;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
Rigidbody2D playerBody = GetComponent<Rigidbody2D>();
if (Input.GetKeyDown("space")){
print("fired");
//playerBody.velocity = new Vector2(playerBody.velocity.x, jumpHeight);
}
if (Input.GetKey(KeyCode.LeftArrow))
{
playerBody.velocity = new Vector2(-moveSpeed, playerBody.velocity.y);
}
if (Input.GetKey(KeyCode.RightArrow))
{
playerBody.velocity = new Vector2(moveSpeed, playerBody.velocity.y);
}
}
}
我也尝试过Keycode.Space,而不是“空格”,这也不起作用
另外由于某种原因,我无法删除或替换 unity3d 标签,但它是用于 2d unity 游戏的。
【问题讨论】:
-
Unity 使用
Debug.Log将消息打印到 Unity 调试控制台。 -
打印也适合我