【问题标题】:Pausing Unity game without "Time.timeScale = 0"在没有“Time.timeScale = 0”的情况下暂停 Unity 游戏
【发布时间】:2014-10-28 22:00:21
【问题描述】:

我正在尝试找到一种在 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;
    }
}

【问题讨论】:

  • 您可以在 gamedev.stackexchange.com 上找到更多关于统一的帮助
  • 没有任何东西可以集成到统一中。但我建议看看状态机,因为当你有不同的状态(暂停/播放)以及进入/退出状态时需要做的事情时,它们会有所帮助。
  • 我知道这个帖子有点老了,但你可以在这里试试我的答案:stackoverflow.com/questions/31718168/pausing-in-unity/…

标签: c# unity3d 2d-games unity3d-2dtools


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-27
    • 1970-01-01
    • 1970-01-01
    • 2016-01-09
    相关资源
    最近更新 更多