Я создаю простую игру, и мой игровой объект (игрок) должен перемещаться вверх, когда нажата клавиша «Пробел» или левая кнопка мыши. нажата.
Вот мой код
Код: Выделить всё
using UnityEngine;
using System.Collections;
public class PixelMovement : MonoBehaviour {
Vector3 velocity = Vector3.zero;
public Vector3 PressVelocity;
public float maxSpeed = 5f;
public float fowardSpeed = 1f;
bool didPress = false;
// Use this for initialization
void Start () {
}
//Do Graphic & Input updates
void update() {
if(Input.GetKeyDown(KeyCode.Space) || Input.GetMouseButtonDown(0)) {
didPress = true;
}
}
//Do physics engine updates here
void FixedUpdate () {
velocity.x = fowardSpeed;
if (didPress == true){
didPress = false;
velocity += PressVelocity;
}
velocity = Vector3.ClampMagnitude(velocity, maxSpeed);
transform.position += velocity * Time.deltaTime;
}
}
Подробнее здесь: https://stackoverflow.com/questions/371 ... -studio-un