Example #1
0
 void OnTriggerEnter2D(Collider2D collisionObject)
 {
     if (collisionObject.gameObject.tag == "Coin")
     {
         GetComponent<AudioSource>().pitch = Random.Range(0.95f, 1.05f);
         GetComponent<AudioSource>().PlayOneShot(coinSound, 0.25f);
         scoreMan.AddCoin();
         Destroy(collisionObject.transform.parent.gameObject);
     }
     if (collisionObject.gameObject.tag == "Health")
     {
         //GetComponent<AudioSource>().pitch = Random.Range(0.95f, 1.05f);
         //GetComponent<AudioSource>().PlayOneShot(coinSound, 0.25f);
         if (curHealth != maxHealth)
         {
             curHealth++;
             Destroy(collisionObject.transform.parent.gameObject);
         }            
     }
     if (collisionObject.gameObject.tag == "Gem")
     {
         GetComponent<AudioSource>().pitch = Random.Range(0.95f, 1.05f);
         GetComponent<AudioSource>().PlayOneShot(coinSound, 0.25f);
         playerLvl.AddEXP(5.0f);
         Destroy(collisionObject.gameObject);
     }
     if (collisionObject.gameObject.tag == "Enemy")
     {
         print("HurtPlayer");
         curHealth--;
         GetComponent<AudioSource>().pitch = Random.Range(0.9f, 1.1f);
         GetComponent<AudioSource>().PlayOneShot(hurtSound, 0.25f);
         shake.DoShake();
         StartCoroutine(HurtPlayer(0.2f));
     }
     if (collisionObject.gameObject.tag == "EnemyArrow")
     {
         print("HurtPlayer");
         curHealth--;
         GetComponent<AudioSource>().pitch = Random.Range(0.9f, 1.1f);
         GetComponent<AudioSource>().PlayOneShot(hurtSound, 0.25f);
         shake.DoShake();
         StartCoroutine(HurtPlayer(0.2f));
     }
     if (collisionObject.gameObject.tag == "Hurt")
     {
         GetComponent<AudioSource>().pitch = Random.Range(0.9f, 1.1f);
         GetComponent<AudioSource>().PlayOneShot(hurtSound, 0.25f);
         print("HurtPlayer");
         curHealth--;
         shake.DoShake();
         StartCoroutine(HurtPlayer(0.2f));
     }
     if (collisionObject.gameObject.tag == "Gear")
     {
         print("KillPlayer");
         ReloadLevel();
     }
 }
Example #2
0
 public void DecreeHealth()
 {
     if (lives > 0)
     {
         --lives;
         livesText.text = lives + "";
         //Am thanh khi mat mang
         if (SoundManager.instance != null)
         {
             SoundManager.instance.PlaySFX(SFX.PLAYER_DIE);
         }
         //Rung man hinh
         shakeCamera.DoShake();
         //Rung dien thoai
         if (Attributes.isVibrationOn())
         {
             Handheld.Vibrate();
         }
         if (lives == 0)
         {
             Debug.Log("Game Over: Lose");
             SetGameState(GAMESTATE.LOSEGAME);
         }
     }
 }
Example #3
0
 // Update is called once per frame
 void Update()
 {
     if (fireRate == 0)
     {
         if (Input.GetButton("Fire1"))
         {
             Shoot();
             shake.DoShake();
         }
     }
     else
     {
         if (Input.GetButton("Fire1") && Time.time > timeToFire)
         {
             timeToFire = Time.time + 1 / fireRate;
             Shoot();
             shake.DoShake();
         }
     }
 }