void OnCollisionEnter(Collision col) { //Store the current position of the ball. //Vector3 ballposition = transform.position; GameObject go = col.gameObject; Vector3 goPos = go.transform.position; // we will just return if there is somthing we dont want to play the effect for. if (go.CompareTag("Ball")) { return; } if (go.CompareTag("Ground")) { return; } if (go.CompareTag("Cannon")) { Cannon c = go.GetComponent <Cannon>(); if (c && ID != BallSourceID.Netural) { //Check if we arent burning before we get hit. bool ex = false; if (!c.IsBurning) { ex = true; } //Apply the damage. c.Heat += DamageAmount; //If we wernt burning before and now are, then explode! if (c.IsBurning && ex) { //Play chicken sound when shot to explosion. AudioPlayer.GetPlayer().PlayMenuSFX(AudioPlayer.MenuSFX.Chicken); c.Explode(); } } return; } // if(col.gameObject.CompareTag("Bot")) // { // if(Active) // { // // print("Active Collision!!"); // } // // } if (go.CompareTag("Target")) { if (StandardHitEffect) { //StandardHitEffect.transform.position = goPos; StandardHitEffect.Play(); } } //If we hit the wall as the bots ball then we will register a miss event. if (go.CompareTag("Wall")) { if (StandardHitEffect) { //StandardHitEffect.transform.position = myTransform.position; StandardHitEffect.Play(); } } }
//Check for ball collisions and apply damage. void OnCollisionEnter(Collision col) { //If we hit some walls if (col.gameObject.CompareTag("Wall")) { if (GetComponent <Rigidbody>().velocity.magnitude > 10.0f) { //print("BOOM!"); //Play sound AudioPlayer.GetPlayer().PlaySound(HitSoundEffect); //Deal the damage Damage(500.0f); } } //If we hit some walls if (col.gameObject.CompareTag("Target")) { if (GetComponent <Rigidbody>().velocity.magnitude > 10.0f) { //print("BOOM!"); //Play sound AudioPlayer.GetPlayer().PlaySound(HitSoundEffect); //Deal the damage Damage(SelfMomentumDamage); //Get the ball we collided with. Target t = col.gameObject.GetComponent <Target>(); t.Damage(TargetMomentumDamage); } } ///If we hit a ball it should turn red now. if (col.gameObject.CompareTag("Ball")) { //Get the ball we collided with. Ball b = col.gameObject.GetComponent <Ball>(); //Only look for active balls! if (b.IsActive()) { if (b.GetBallSourceID() != Ball.BallSourceID.Netural && b.GetBallSourceID() != Ball.BallSourceID.Enemy) { //Set the Damage Damage(b.DamageAmount); //And we pop the ball. b.Pop(); //Call the balls hit target function to handle the stat registering b.HitTarget(); // if(b.GetBallSourceID() == Ball.BallSourceID.Bot) // { // // //Send The Message // GameObjectTracker.GetGOT().EnemyHit(); // // } //Play the sound. AudioPlayer.GetPlayer().PlaySound(HitSoundEffect); } } //Here we do a test to ONLY pick up active netural balls and nothing else. if (b.GetBallSourceID() == Ball.BallSourceID.Netural) { //We have to make sure we have a cannon attached to pick up a ball and we make sure sheild is not on. if (connectorcontroller.HasCannon()) { //Call attach for the cannon that we collide with. if (connectorcontroller.GetCannon().PickupBall(b)) { //Set the ID to the ball b.SetBallSourceID(Ball.BallSourceID.Enemy); //Play the effect for picking up a ball. if (Collection) { //Play the collection animation. Collection.Play(); } } } } } //Ball Collision Check //Check if we collide with a cannon. if (col.gameObject.CompareTag("Cannon") && !IsDestroyed()) { Cannon c = col.gameObject.GetComponent <Cannon>(); if (c.GetComponent <Rigidbody>().velocity.magnitude > 10.0f || c.IsBurning) { //print("BOOM!"); //Play sound AudioPlayer.GetPlayer().PlaySound(HitSoundEffect); //Deal the damage Damage(c.GetComponent <Rigidbody>().mass); c.Explode(); //Get the ball we collided with. //Target t = col.gameObject.GetComponent<Target>(); //t.Damage(500.0f); } //Call attach for the cannon that we collide with. if (connectorcontroller.AttachCannon(c)) { cooldownTimer = CoolDownTime - 0.5f; currentState = BaseEnemy.ActionState.CoolDown; } } } //All Collisions Check
void OnCollisionEnter(Collision col) { //If we hit some walls if (col.gameObject.CompareTag("Cannon")) { Cannon c = col.gameObject.GetComponent <Cannon>(); if (GetComponent <Rigidbody>().velocity.magnitude > 10.0f || c.IsBurning) { //print("BOOM!"); //Play sound AudioPlayer.GetPlayer().PlaySound(HitSoundEffect); //Deal the damage Damage(col.rigidbody.mass); c.Explode(); //Get the ball we collided with. //Target t = col.gameObject.GetComponent<Target>(); //t.Damage(500.0f); } } ///If we hit a ball it should turn red now. if (col.gameObject.CompareTag("Ball")) { //Get the ball we collided with. Ball b = col.gameObject.GetComponent <Ball>(); //Only look for active balls! if (b.IsActive() && b.GetBallSourceID() != Ball.BallSourceID.Netural) { //Damage Damage(b.DamageAmount); //audio.clip = HitSoundEffect; AudioPlayer.GetPlayer().PlaySound(HitSoundEffect); //Call the balls hit target function to handle the stat registering b.HitTarget(); // if(b.GetBallSourceID() == Ball.BallSourceID.Bot) // { // //Send the message. Its about sending the message // GameObjectTracker.GetGOT().TargetHit(); // } //Pop the ball if it isnt shoot through. if (!b.IsShootThrough()) { b.Pop(); } } } }