void OnCollisionEnter(Collision collision) { if (collision.gameObject.tag == "playerLaser" && collision.gameObject.name != "LaserFire") { Debug.Log("collision!"); int damage = PlayerPrefs.GetInt("W1Damage") + 1; if (isVenting) { damage *= 3; } steamBotHP -= damage; AudioSource.PlayClipAtPoint(hitSound, transform.position); tk2dTextMesh dT = damageNumber.GetComponent <tk2dTextMesh>(); dT.text = damage.ToString(); GameObject.Instantiate(damageNumber, new Vector3(collision.transform.position.x, collision.transform.position.y, collision.transform.position.z), Quaternion.identity); if (!isVenting) { fire = true; } Destroy(collision.gameObject); if (steamBotHP <= 0) { if (!hasExploded) { Transform clone = (Transform)Instantiate(explosionMesh, transform.position, Quaternion.Euler(90, 0, 0)); SplitMeshIntoTriangles explodeScript = (SplitMeshIntoTriangles)clone.GetComponent(typeof(SplitMeshIntoTriangles)); explodeScript.blowUp(); hasExploded = true; AudioSource.PlayClipAtPoint(deathSound, transform.position); GameObject cam = GameObject.Find("tk2dCamera"); CameraShake cS = (CameraShake)cam.GetComponent(typeof(CameraShake)); cS.shakeCam(); } steamBotHP = 20; // give the player credit GameObject level = GameObject.Find("Level"); LevelLogic LL = level.GetComponent <LevelLogic>(); LL.destroyCount += 1; Destroy(gameObject); } } }
void OnCollisionEnter(Collision collision) { if (collision.gameObject.tag == "playerLaser") { Debug.Log("collision!"); int damage = PlayerPrefs.GetInt("W1Damage") + 1; miniBossHP -= damage; AudioSource.PlayClipAtPoint(hitSound, transform.position); tk2dTextMesh dT = damageNumber.GetComponent <tk2dTextMesh>(); dT.text = damage.ToString(); GameObject.Instantiate(damageNumber, new Vector3(collision.transform.position.x, collision.transform.position.y, collision.transform.position.z), Quaternion.identity); Destroy(collision.gameObject); if (miniBossHP <= 0) { Transform clone = (Transform)Instantiate(explosionMesh, transform.position, Quaternion.Euler(90, 0, 0)); SplitMeshIntoTriangles explodeScript = (SplitMeshIntoTriangles)clone.GetComponent(typeof(SplitMeshIntoTriangles)); explodeScript.blowUp(); miniBossHP = 500; // give the player credit GameObject level = GameObject.Find("Level"); LevelLogic LL = level.GetComponent <LevelLogic>(); LL.destroyCount += 1; Destroy(gameObject); } } }
void healthBar() { //Debug.Log("TAKE DAMAGE : CURRENT HEALTH" + currentHp); //Debug.Log("TAKE DAMAGE : CURRENT SHIELD" + currentShield); // shield bar if (currentShield <= 5) { GameObject s5 = GameObject.FindGameObjectWithTag("shield5"); Destroy(s5); } if (currentShield <= 4) { GameObject s4 = GameObject.FindGameObjectWithTag("shield4"); Destroy(s4); } if (currentShield <= 3) { GameObject s3 = GameObject.FindGameObjectWithTag("shield3"); Destroy(s3); } if (currentShield <= 2) { GameObject s2 = GameObject.FindGameObjectWithTag("shield2"); Destroy(s2); } if (currentShield <= 1) { GameObject s1 = GameObject.FindGameObjectWithTag("shield1"); Destroy(s1); } if (currentShield <= 0) { GameObject s0 = GameObject.FindGameObjectWithTag("shield0"); Destroy(s0); // health bar if (currentHp <= 5) { GameObject h5 = GameObject.FindGameObjectWithTag("hp5"); Destroy(h5); } if (currentHp <= 4) { GameObject h4 = GameObject.FindGameObjectWithTag("hp4"); Destroy(h4); } if (currentHp <= 3) { GameObject h3 = GameObject.FindGameObjectWithTag("hp3"); Destroy(h3); } if (currentHp <= 2) { GameObject h2 = GameObject.FindGameObjectWithTag("hp2"); Destroy(h2); } if (currentHp <= 1) { GameObject h1 = GameObject.FindGameObjectWithTag("hp1"); Destroy(h1); } } // WHAT HAPPENS ON DEATH if (currentHp <= 0) { GameObject h0 = GameObject.FindGameObjectWithTag("hp0"); Destroy(h0); if (!hasExploded) { int rotationAngle = 0; if (lastDir == 0) { rotationAngle = -180; } else if (lastDir == 1) { rotationAngle = 0; } Transform clone = (Transform)Instantiate(explosionMesh, transform.position, Quaternion.Euler(90, rotationAngle, 0)); SplitMeshIntoTriangles explodeScript = (SplitMeshIntoTriangles)clone.GetComponent(typeof(SplitMeshIntoTriangles)); explodeScript.blowUp(); hasExploded = true; } Destroy(GameObject.Find("Thruster")); isDead = true; transform.collider.enabled = false; AudioSource.PlayClipAtPoint(gameOverSound, transform.position); currentHp = PlayerPrefs.GetInt("PHealth"); //screenManager.currentScreen = 2; //screenManager.isLive = false; } }
void OnParticleCollision(GameObject collision) { //Debug.Log(collision.name); int checkStatus; GameObject laserGun = GameObject.Find("Player1(Clone)/LaserGun"); LaserGun gunScript = laserGun.GetComponent <LaserGun>(); checkStatus = gunScript.status; if (collision.name == "LaserFire" && checkStatus == 2) { //Debug.Log("Hit with laser!"); int damage = PlayerPrefs.GetInt("W1Damage") + 3; if (isVenting) { damage *= 3; } steamBotHP -= damage; AudioSource.PlayClipAtPoint(hitSound, transform.position); tk2dTextMesh dT = damageNumber.GetComponent <tk2dTextMesh>(); dT.text = damage.ToString(); GameObject.Instantiate(damageNumber, new Vector3(transform.position.x, transform.position.y + 8, transform.position.z), Quaternion.identity); if (!isVenting) { fire = true; } //Destroy(collision); if (steamBotHP <= 0) { if (!hasExploded) { Transform clone = (Transform)Instantiate(explosionMesh, transform.position, Quaternion.Euler(90, 0, 0)); SplitMeshIntoTriangles explodeScript = (SplitMeshIntoTriangles)clone.GetComponent(typeof(SplitMeshIntoTriangles)); explodeScript.blowUp(); hasExploded = true; AudioSource.PlayClipAtPoint(deathSound, transform.position); GameObject cam = GameObject.Find("tk2dCamera"); CameraShake cS = (CameraShake)cam.GetComponent(typeof(CameraShake)); cS.shakeCam(); } steamBotHP = 20; // give the player credit GameObject level = GameObject.Find("Level"); LevelLogic LL = level.GetComponent <LevelLogic>(); LL.destroyCount += 1; Destroy(gameObject); } } }
void OnParticleCollision(GameObject collision) { //Debug.Log(collision.name); int checkStatus; GameObject laserGun = GameObject.Find("Player1(Clone)/LaserGun"); LaserGun gunScript = laserGun.GetComponent <LaserGun>(); checkStatus = gunScript.status; if (collision.name == "LaserFire" && checkStatus == 2) { int damage = PlayerPrefs.GetInt("W1Damage") + 1; clusterBotHP -= damage; AudioSource.PlayClipAtPoint(hitSound, transform.position); tk2dTextMesh dT = damageNumber.GetComponent <tk2dTextMesh>(); dT.text = damage.ToString(); GameObject.Instantiate(damageNumber, new Vector3(transform.position.x, transform.position.y + 8, transform.position.z), Quaternion.identity); Vector3 headingBullet = transform.position - player.transform.position; if (headingBullet.x > 0) { transform.position = new Vector3(transform.position.x + 0.25f, transform.position.y, 0); } else if (headingBullet.x <= 0) { transform.position = new Vector3(transform.position.x - 0.25f, transform.position.y, 0); } //float distance = headingBullet.magnitude; //Vector3 direction = headingBullet / distance; // This is now the normalized direction. //transform.rigidbody.AddForce(direction.normalized * 100); //Destroy(collision.gameObject); // calculate knockback // if (clusterBotHP <= 0) { Vector3 heading = transform.position - player.position; Debug.Log("heading: " + heading); if (heading.x > 0) { facing = 0.0f; } else if (heading.x <= 0) { facing = -180.0f; } AudioSource.PlayClipAtPoint(deathSound, transform.position); if (!hasExploded) { Transform clone = (Transform)Instantiate(explosionMesh, transform.position, Quaternion.Euler(90, facing, 0)); SplitMeshIntoTriangles explodeScript = (SplitMeshIntoTriangles)clone.GetComponent(typeof(SplitMeshIntoTriangles)); explodeScript.blowUp(); GameObject cam = GameObject.Find("tk2dCamera"); CameraShake cS = (CameraShake)cam.GetComponent(typeof(CameraShake)); cS.shakeCam(); hasExploded = true; } clusterBotHP = 20; // give the player credit GameObject level = GameObject.Find("Level"); LevelLogic LL = level.GetComponent <LevelLogic>(); LL.destroyCount += 1; Destroy(gameObject); } } }