2

我试图找到一种方法来暂停我在 Unity 中的游戏,而不使用“Time.timeScale = 0;”。我想改变它的原因是我想让角色在游戏暂停时播放动画。有没有办法改变这个脚本,使重力和前进速度只在玩家点击空间后“设置”?或者有没有更好的方法来解决这个问题?

这是脚本:

public class PlayerMove : MonoBehaviour {

    Vector3 velocity = Vector3.zero;
    public Vector3 gravity;
    public Vector3 FlyVelocity;
    public float maxSpeed = 5f;
    public float forwardSpeed = 1f; 

    bool didFly = false;
    bool dead = false;
    float deathCooldown;
    Animator animator;

    // Use this for initialization
    void Start () {
        animator = GetComponentInChildren<Animator>();
    }

    // Do Graphic & Input updates here
    void Update(){
        if (dead) {
            deathCooldown -= Time.deltaTime;

            if (deathCooldown <= 0) {
                if (Input.GetKeyDown(KeyCode.Space) || Input.GetMouseButtonDown(0) ) {
                Application.LoadLevel( Application.loadedLevel );
                    }
                }
            }
        if (Input.GetKeyDown(KeyCode.Space) || Input.GetMouseButtonDown(0) ) {
            didFly = true;
            animator.SetTrigger ("DoFly");
        }
    }

    void OnCollisionEnter2D(Collision2D collision) {
        animator.SetTrigger ("Death");
        dead = true;
    }

    // Do physics engine updates here
    void FixedUpdate () {
        if (dead)
            return;

        velocity += gravity * Time.deltaTime;
        velocity.x = forwardSpeed;

        if(didFly == true) {
            didFly = false;
            velocity += FlyVelocity;
        }

        velocity = Vector3.ClampMagnitude(velocity, maxSpeed);

        transform.position += velocity * Time.deltaTime;

        deathCooldown = 0.5f;
    }
}
4

1 回答 1

0

如果您使用的是 Mechanim,您可以使用Animator.Update从脚本更新动画状态,即使实际时间比例为零。

不确定旧动画是否可以使用该技巧。

于 2014-09-04T08:47:03.867 回答