2

「Time.timeScale = 0;」を使用せずに Unity でゲームを一時停止する方法を見つけようとしています。これを変更したい理由は、ゲームの一時停止中にキャラクターにアニメーションを再生させたいからです。プレイヤーがスペースをクリックした後にのみ重力と前進速度が「設定」されるように、このスクリプトを変更する方法はありますか? または、問題を解決するためのより良い方法はありますか?

これはスクリプトです:

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 に答える