void OnCollisionEnter(Collision collision) { Collider collider = collision.collider; if (collider.CompareTag("Alien")) { Alien enemy = collider.gameObject.GetComponent <Alien>(); enemy.die(); die(); } else if (collider.CompareTag("UFO")) { UFO ufo = collider.gameObject.GetComponent <UFO>(); ufo.die(); GameObject g = GameObject.Find("Environment"); Environment globalObj = g.GetComponent <Environment>(); globalObj.score += Random.Range(50, 200); die(); } else if (collider.CompareTag("Platform")) { Platform platform = collider.gameObject.GetComponent <Platform>(); platform.takeDamage(); die(); } else { Debug.Log("Collided with " + collider.tag); } }
void OnCollisionEnter(Collision collision) { Collider collider = collision.collider; // right itself if (!collider.CompareTag("Alien")) { grounded = true; doubleJump = true; } if (collider.CompareTag("BuilderSpawn")) { Debug.Log("Now a buidler"); builder = true; gameObject.renderer.material = BuilderMaterial; updateClass(); } else if (collider.CompareTag("FighterSpawn")) { Debug.Log("Now a gfighter"); gameObject.renderer.material = FighterMaterial; builder = false; updateClass(); } else if (collider.CompareTag("Alien")) { // if shielded if (shield.activated) { Alien alien = collider.GetComponent <Alien>(); alien.die(); } else { takeDamage(); } } else if (collider.CompareTag("UFO")) { // if shielded if (shield.activated) { GameObject g = GameObject.Find("Environment"); Environment globalObj = g.GetComponent <Environment>(); globalObj.score += 300; UFO ufo = collider.GetComponent <UFO>(); ufo.die(); } else { takeDamage(); } } // if it's the builderspawn }
void Update() { checkHumans(); // camera logic if (Input.GetButtonDown("Camera")) { // switch camera fpcam.active = !fpcam.active; maincam.active = !maincam.active; } // check the ufo, if it exists, check if its out of boundaries if (ufo != null) { if (ufo.transform.position.x < tl.x || ufo.transform.position.x > br.x) { ufo.die(); } // check, for each human, if it is within the bounds of the ufo's position, else { for (int i = 0; i < humans.GetLength(0); i++) { if (humans[i] != null) { if (humans[i].transform.position.x <= ufo.transform.position.x + 0.5f && humans[i].transform.position.x >= ufo.transform.position.x - 0.5f) { humans[i].floatUp(); ufo.stop(); } } } } } // chance to spawn ufo else { float chance = Random.Range(0.0f, 1.0f); if (chance < ufoChance) { spawnUFO(); } } // check each alien, if it goes past the boundary, change all aliens directions and return foreach (Alien a in aliens) { // if going vertical, ignore if (a == null) { continue; } if (a.vertical) { break; } // if horizontal check to see if hit edge if ((!a.right && a.transform.position.x - a.getVelocity() < tl.x) || (a.right && a.transform.position.x + a.getVelocity() > br.x)) { foreach (Alien b in aliens) { b.changeDirection(); } break; } } }
void OnCollisionEnter(Collision collision) { Collider collider = collision.collider; if (collider.CompareTag("Ship")) { Ship player = collider.gameObject.GetComponent <Ship>(); player.takeDamage(); die(); } else if (collider.CompareTag("Platform")) { Platform platform = collider.gameObject.GetComponent <Platform>(); platform.takeDamage(); die(); } else if (collider.CompareTag("Alien")) { if (reflected) { Alien alien = collider.gameObject.GetComponent <Alien>(); alien.takeDamage(); die(); } } else if (collider.CompareTag("UFO")) { if (reflected) { UFO ufo = collider.gameObject.GetComponent <UFO>(); ufo.die(); die(); GameObject g = GameObject.Find("Environment"); Environment globalObj = g.GetComponent <Environment>(); globalObj.score += 300; } } else if (collider.CompareTag("Shield")) { // reflect only if player isn't shielded Shield shield = collider.GetComponent <Shield>(); if (shield.activated) { reflected = true; Vector3 avg = new Vector3(0, 0, 0); // average over the collision's contact points is the normal foreach (ContactPoint contact in collision.contacts) { avg += contact.normal; } avg /= collision.contacts.GetLength(0); Debug.Log("his"); Debug.Log(avg); direction = Vector3.Reflect(gameObject.transform.position, avg); direction.Normalize(); direction += shield.rigidbody.velocity; // TODO: add to the direction vector of the player } else { shield.transform.parent.GetComponent <Player1>().takeDamage(); die(); } } else if (collider.CompareTag("Player")) { // TODO: Figure out why it never hits player when shield is down Debug.Log("Hit player. should not happen"); Shield shield = collider.GetComponent <Player1>().shield; if (shield.activated) { reflected = true; Vector3 avg = new Vector3(0, 0, 0); // average over the collision's contact points is the normal foreach (ContactPoint contact in collision.contacts) { avg += contact.normal; } avg /= collision.contacts.GetLength(0); Debug.Log("his"); Debug.Log(avg); direction = Vector3.Reflect(gameObject.transform.position, avg); direction.Normalize(); direction += rigidbody.velocity; // TODO: add to the direction vector of the player } else { shield.transform.parent.GetComponent <Player1>().takeDamage(); die(); } } else if (collider.CompareTag("Human")) { Human human = collider.gameObject.GetComponent <Human>(); human.takeDamage(); die(); } else if (collider.CompareTag("Ground")) { die(); } else { Debug.Log("Collided with " + collider.tag); } }