【发布时间】:2014-03-19 17:18:19
【问题描述】:
嗨,我想知道是否有人可以帮助我修复练习代码(我在制作真实的东西之前制作练习代码,因为它就是我滚动的方式)它基本上是一个需要用户点击屏幕才能完成的对象它不会像飞扬的小鸟那样接触地面,但是尽管我已将重力正确应用于精灵,但我无法修复速度部分(我编码的是每次用户用鼠标单击或点击空格键时,对象会向上移动就像飞扬的鸟)
using UnityEngine;
using System.Collections;
public class BirdMovment : MonoBehaviour {
Vector3 Velocity = Vector3.zero;
public Vector3 gravity;
public Vector3 flapVelocity;
public float maxSpeed = 5f;
bool didFlap = false;
// Use this for initialization
void Start () {
}
void update (){
if (Input.GetKeyDown (KeyCode.Mouse0))
{
didFlap = true;
}
}
// Update is called once per frame
void FixedUpdate () {
Velocity += gravity* Time.deltaTime;
if (didFlap) {
didFlap = false;
Velocity += flapVelocity;
}
Velocity = Vector3.ClampMagnitude (Velocity, maxSpeed);
transform.position += Velocity * Time.deltaTime;
}
}
您能否修复错误,因为每次我为精灵广告设置统一的速度时,运行程序精灵一直在下降,无论我点击或点击空格键多少,精灵都不会停止下降如果我增加速度
【问题讨论】:
标签: c# unity3d 2d flappy-bird-clone