2015-11-21 23 views
1

我有一個腳本附加到我的播放器中,其中有IEnumerator OnTriggerExit2D。其中有一個time.time scale等於0,這使得整個遊戲在與標籤對象發生碰撞後暫停。我這樣設置,以便我的玩家在碰撞後的某個時間停止(我使用了yield return new WaitForSeconds)。如何繞過Time.time刻度

我的問題是;有沒有辦法讓我的球員不受time.time scale的影響,但在發生碰撞後仍然停止,所以我的球員在整個比賽仍然暫停時仍然運作。這裏是我的腳本:

public class Player : MonoBehaviour { 

    public float speed = 15f; 
    private Vector3 target; 
    public Player playerMovementRef; 
    void Start() { 
     target = transform.position; 
    } 

    void Update() { 
     if (Input.GetMouseButtonDown(0)) { 
      target = Camera.main.ScreenToWorldPoint(Input.mousePosition); 
      target.z = transform.position.z; 
     } 
     transform.position = Vector3.MoveTowards(transform.position, target, speed * Time.deltaTime); 
    } 

    IEnumerator OnTriggerExit2D (Collider2D other){ 
     if (other.tag == "Bouncy object") 
      playerMovementRef.enabled = false; 
     yield return new WaitForSeconds (0.35f); 
     Time.timeScale = 0f; 
     playerMovementRef.enabled = true; 
    } 
} 

回答

2

案例1

您可以從更新刪除Time.deltaTime。 即使您將時間刻度設置爲0,仍然會調用更新。只有Time.deltaTime將爲0,因此您的播放器不會移動。

你可以把一些常數值,而不是使用Time.deltaTime來移動你的播放器。 雖然它不會幀率獨立,你可以讓你的球員移動。

案例2

您可以禁用(GetComponent()。啓用=假)均來自除您的播放器,而不是Time.timescale設置爲0

+0

謝謝所有其他遊戲物體的剛體,但我已經知道了。 –

+0

太棒了!祝你好運〜 –