void OnTriggerEnter(Collider other) { if (!isServer) { return; } //Set target only if the current target is no longer active and definitions allow if ((currentTarget == null || !currentTarget.activeSelf) && collideDefinitions.collidesWith(other)) { RpcSetTarget(other.gameObject); print("Tracking enemy " + other); } }
void OnTriggerEnter(Collider other) { //ignore detectors if (CompareTag("Player Detector")) { return; } if (CompareTag("Friend Detector")) { return; } //only collide if definitions say so, on the screen, and not already dead if (collideDefinition.collidesWith(other) && transform.position.x < MAX_X_COLLIDE && !startedDeathCoroutine) { //special consideration for powerups if (other.CompareTag("Powerup") && isServer) { other.transform.parent.gameObject.GetComponent <PowerUpHandler>().CmdActivate(gameObject); } DealDamage(other.gameObject); //create contact effects, if any if (contactEffectList.Length > 0) { Pools.Initialize( contactEffectList[Random.Range(0, contactEffectList.Length)], other.transform.position, Quaternion.identity); } if (contactSoundList.Length > 0) { GameObject audio = Pools.Initialize( contactSoundList[Random.Range(0, contactSoundList.Length)], other.transform.position, Quaternion.identity); audio.GetComponent <AudioSource>().Play(); } //kill when current health <= 0 if (isServer && currentHealth <= 0 && !startedDeathCoroutine) { startedDeathCoroutine = true; StartCoroutine(DeathCoroutine()); } } }
void OnTriggerEnter(Collider other) { //On collision, damage the next object and continue from there if (collideDefinitions.collidesWith(other)) { //initial damage is handled by the collision handler //find information between the two locations Vector3 direction = rootTransform.position - other.transform.position; Vector3 middle = (rootTransform.position + other.transform.position) / 2.0f; float factor = 1.5f; //Create the rod Transform rodTransform = rod.GetComponent <Transform>(); rodTransform.position = middle; rodTransform.rotation = Quaternion.FromToRotation(Vector3.right, direction); rodTransform.Rotate(new Vector3(90, 0, 0)); GameObject newRod = Pools.Initialize(rod, rodTransform.position, rodTransform.rotation); newRod.transform.localScale = new Vector3(direction.magnitude * factor, 0.5f, 0.5f); //move this handler onto the other's location and reset it rootTransform.position = other.transform.position; detector.radius = 0; //damage the other element ObjectCollisionHandler handler = other.GetComponent <ObjectCollisionHandler>(); //if no collider exists, then attempt to take from parent GameObject otherObject = other.gameObject; while (handler == null) { otherObject = otherObject.transform.parent.gameObject; handler = otherObject.GetComponentInParent <ObjectCollisionHandler>(); } handler.Damage(damageAmount, tag); Pools.Initialize(explosion, rootTransform.position, rootTransform.rotation); //increase hits performed hitsPerformed++; } }