// Use this for initialization override protected void Start() { if (type == TurretType.man) { health = 1; } else if (type == TurretType.boss) { health = 8; } else { health = 5; } base.Start(); guy = FindObjectOfType(typeof(PE_Guy)) as PE_Guy; }
void FixedUpdate() { // Handle the timestep for each object float dt = Time.fixedDeltaTime; float vertExtent = Camera.main.camera.orthographicSize; float bottom = this.transform.position.y - vertExtent; foreach (PE_Obj po in objs) { //Adjust Camera if guy has moved pass mid way point of the screen if (OffScreen(po) && (po.coll == PE_Collider.friendlyBullet || po.coll == PE_Collider.enemyBullet)) { objs.Remove(po); Destroy(po.gameObject); break; } if (po.transform.position.y < bottom - 5 && (po.coll == PE_Collider.guy)) { PE_Guy guy = po.GetComponent <PE_Guy> (); if (!guy.isDead) { guy.death(true, po.transform.position); } } if (po.coll == PE_Collider.guy && po.transform.position.x > this.transform.position.x) { Vector3 newPos = this.transform.position; newPos.x = po.transform.position.x; this.transform.position = newPos; } TimeStep(po, dt); } // Resolve collisions // Finalize positions foreach (PE_Obj po in objs) { po.transform.position = po.pos1; } }
override protected void ResolveCollisionWith(PE_Obj that) { switch (this.coll) { case PE_Collider.enemy: switch (that.coll) { case PE_Collider.platform: // collide with platform Vector3 thatP = that.transform.position; Vector3 newPos = transform.position; float boxSizeY = this.GetComponent <BoxCollider> ().size.y; newPos.y = thatP.y + (this.transform.lossyScale.y * .5f * boxSizeY) + (that.transform.lossyScale.y / 2); transform.position = newPos; vel.y = 0; break; case PE_Collider.guy: // collide with guy PE_Guy guy = that.GetComponent <PE_Guy> (); if (!guy.isDead) { guy.death(false, that.transform.position); } break; case PE_Collider.friendlyBullet: // collide with friendlyBullet PhysEngine.objs.Remove(that.GetComponent <PE_Obj>()); Destroy(that.gameObject); PhysEngine.objs.Remove(this.GetComponent <PE_Obj>()); Destroy(this.gameObject); break; } break; } }