2014-09-04 3 views
2

"Time.timeScale = 0;"을 사용하지 않고 Unity에서 게임을 일시 중지 할 방법을 찾으려고합니다. 이것을 바꾸고 싶은 이유는 게임이 일시 정지 된 상태에서 캐릭터를 애니메이션으로 만들고 싶기 때문입니다. 이 스크립트를 변경하여 플레이어가 공간을 클릭 한 후에 중력과 전진 속도 만 "설정"되는 방법이 있습니까? 아니면 문제를 해결할 더 좋은 방법이 있습니까? 당신이 Mechanim를 사용하는 경우"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; 
    } 
} 
+0

gamedev.stackexchange.com – Sayse

+0

에 통일을위한 도움이 더 필요할 수 있습니다. 하지만 상태 머신을 살펴 보는 것이 좋습니다. 왜냐하면이 상태 (일시 중지됨/재생 중)와 다른 상태 (상태 일시 중지/종료시 수행해야 할 상황)가있을 때 도움이되기 때문입니다. – Imapler

+0

이 스레드가 조금 오래되었음을 알고 있지만 여기 내 대답을 시도 할 수 있습니다 : http://stackoverflow.com/questions/31718168/pausing-in-unity/31718377#31718377 – NeverHopeless

답변

0

당신이 실제 시간 규모가 제로 Animator.Update 동안에도 사용하여 스크립트 애니메이션 상태를 업데이트 할 수 있습니다 :

는 스크립트입니다.

레거시 애니메이션에서 트릭이 가능한지 확실하지 않습니다.

관련 문제