Exemplo n.º 1
0
 private void OnCollisionEnter2D(Collision2D collision)
 {
     if (collision.collider.tag == "DeathTrap")
     {
         gameManager.EndGame();
         Debug.Log("You are death");
     }
 }
Exemplo n.º 2
0
 // Update is called once per frame
 void Update()
 {
     // Debug.Log(player.position);
     if (rb.position.y < 0)
     {
         playerCollisionScript.isAlive = false;
         gameManager.EndGame();
     }
     // if (transform.position.y > (ground.position.y + 1.2)) {
     //     canJump = false;
     // } else {
     //     canJump = true;
     // }
 }
Exemplo n.º 3
0
 public bool CheckHealth()
 {
     if (currentHealth == maxHealth)
     {
         return(false);
     }
     else if (currentHealth <= 0)
     {
         gameManager.EndGame();
         return(false);
     }
     else
     {
         return(true);
     }
 }
Exemplo n.º 4
0
    // this method is invoked when a collision is detected
    void OnCollisionEnter(Collision collisionInfo)
    {
        // Collision object has many classes and other objects that are able to be utilized for collision responses.
        // instead of creating a variable whose type is that of the component we want to manipulate.
        // we can call GetComponent<>().
        // the generic type of GetComponent<>() is the type of the component we want to manipulate.
        // the two are equal, we can still access all of the methods and properties of the given component.
        if (collisionInfo.collider.tag == "Obstacle")
        {
            Debug.Log(collisionInfo);
            isAlive = false;
            // GetComponent<PlayerMovement>().enabled = false;
            playerMovementScript.enabled = false;

            // similarly we have FindObjectOfType which in this case will allow us to access the methods and properties of GameManager
            // using this is not as performant as creating a direct reference with a variable
            gameManager.EndGame();
        }
    }