Exemple #1
0
 void OnTriggerEnter(Collider other)
 {
     if (other.gameObject.tag == "enemyH")
     {
         Destroy(gameObject);
         DestroyObject(other.gameObject);
         gameManager.GameOver();
     }
 }
Exemple #2
0
    // Update is called once per frame
    void Update()
    {
        //Detecting button can not write in FixedUpdated() method,
        //because detection is once per frame and FixedUpdate may be triggered multiple times per frame.
        //Dash Function, Triggered once when the button is pressed
        if (Input.GetKeyDown(KeyCode.DownArrow) && canJump && dashSwitch == true && GameManager1.GameStart)
        {
            //triger Dash of three frames animation
            animator.SetBool("dash", true);
            //Make the hero move a distance down the Y axis
            GetComponent <BoxCollider2D>().size   = new Vector2(bodySize.x, bodySize.y * 0.5f);
            GetComponent <BoxCollider2D>().offset = new Vector2(bodyCenter.x, bodyCenter.y - 0.19f);

            dashSwitch = false;
            //Keep dash time at 1 seconds
            Invoke("Dash", 0.5f);
        }

        //jump script could also put in FixedUpdate but the unit time should be modified,
        //or there will be delay on jump
        canJump = onGround();
        if (Input.GetKeyDown(KeyCode.UpArrow) && canJump && GameManager1.GameStart)
        {
            GetComponent <Rigidbody2D>().AddForce(new Vector2(0, jumpForce * 10));
            //jump animation active
            animator.SetBool("jump", true);
        }
        else
        {
            //jump animation deactive
            animator.SetBool("jump", !canJump);
        }

        //death trigger
        if (playerDeath == true || playerWin == true)
        {
            gameManager.GameOver();
        }
    }
Exemple #3
0
 private void OnTriggerEnter(Collider other)
 {
     if (gameManager.isGameActive)
     {
         if (other.gameObject.CompareTag("Enemy"))
         {
             explosion.Play();
             Destroy(other.gameObject);
             lifes -= 1;
             Destroy(lifeSprites[lifes]);
         }
         else if (other.gameObject.CompareTag("Moon"))
         {
             lifes = 0;
         }
         if (lifes <= 0)
         {
             bigExplosion.Play();
             gameManager.GameOver();
             playerRB.useGravity = true;
             Destroy(gameObject, 3.0f);
         }
     }
 }