void OnCollisionEnter(Collision collision) // --> when the ball enter on collision with the targget { if (collision.relativeVelocity.magnitude > MinMagnitude && !b_MoveObject) // minimum magnitude et the Target don't move. { if (b_Drop_Target) { Desactivate_Object(); // Desactivate Object } for (var j = 0; j < Parent_Manager.Length; j++) { Parent_Manager[j].SendMessage(functionToCall, index); // Call Parents Mission script } if (!sound_.isPlaying && Sfx_Hit) { sound_.PlayOneShot(Sfx_Hit, 1); // Play a sound if needed } if (obj_Game_Manager != null) { if (gameManager) { gameManager.F_Mode_BONUS_Counter(); // Send Message to the gameManager(Manager_Game.js) Add 1 to BONUS_Global_Hit_Counter } if (gameManager) { gameManager.Add_Score(Points); // Send Message to the gameManager(Manager_Game.js) Add Points to Add_Score } } if (Toy) { toy.PlayAnimationNumber(AnimNum); // Play toy animation if needed } } }
void OnTriggerEnter(Collider other) // --> When the ball enter the trigger { if (other.tag == "Ball") { for (var j = 0; j < Parent_Manager.Length; j++) { Parent_Manager[j].SendMessage(functionToCall, index); // Call Parents Mission script } if (!sound_.isPlaying && Sfx_Hit) { sound_.PlayOneShot(Sfx_Hit); // Play a sound if needed } if (obj_Game_Manager != null) { if (gameManager) { gameManager.F_Mode_BONUS_Counter(); // Send Message to the gameManager(Manager_Game.js) Add 1 to BONUS_Global_Hit_Counter } if (gameManager) { gameManager.Add_Score(Points); // Send Message to the gameManager(Manager_Game.js) Add Points to Add_Score } } if (Toy) { toy.PlayAnimationNumber(AnimNum); // Play toy animation if needed } } }
void OnCollisionEnter(Collision collision) // --> Detect collision when bumper enter on collision with other objects { ContactPoint[] tmpContact = collision.contacts; foreach (ContactPoint contact in tmpContact) // if there is a collision : { Rigidbody rb = contact.otherCollider.GetComponent <Rigidbody>(); // Access rigidbody Component float t = collision.relativeVelocity.magnitude; // save the collision.relativeVelocity.magnitude value rb.velocity = new Vector3(rb.velocity.x * .25f, rb.velocity.y * .25f, rb.velocity.z * .25f); // reduce the velocity at the impact. Better feeling with the slingshot rb.AddForce(-1 * contact.normal * bumperForce, ForceMode.VelocityChange); // Add Force } if (Sfx_Hit) { sound_.PlayOneShot(Sfx_Hit); // Play a sound } for (var j = 0; j < Parent_Manager.Length; j++) { Parent_Manager[j].SendMessage(functionToCall, index); // Call Parents Mission script } if (obj_Game_Manager != null) { if (gameManager) { gameManager.F_Mode_BONUS_Counter(); // Send Message to the gameManager(Manager_Game.js) Add 1 to BONUS_Global_Hit_Counter } if (gameManager) { gameManager.Add_Score(Points); // Send Message to the gameManager(Manager_Game.js) Add Points to Add_Score } } if (obj_Led) { Led_Renderer.Led_On_With_Timer(.2f); // If Obj_Led. Switch On the Led during .2 seconds } if (Toy) { toy.PlayAnimationNumber(AnimNum); // Play toy animation if needed } if (Toys.Length > 0) // Play more than One animation { for (var i = 0; i < Toys.Length; i++) { Toys[i].PlayAnimationNumber(AnimNums[i]); } } }
void OnCollisionEnter(Collision collision) // --> OnCollisionEnter with the ball { Rigidbody rb = collision.gameObject.GetComponent <Rigidbody>(); if (rb != null && collision.relativeVelocity.magnitude > ForceMinimum) { if (collision.relativeVelocity.magnitude < relativeVelocityMax) { //Debug.Log("Yipo"); float t = collision.relativeVelocity.magnitude; rb.velocity = new Vector3(rb.velocity.x * .5f, rb.velocity.y * .5f, rb.velocity.z * .5f); // reduce the velocity at the impact. Better feeling with the slingshot rb.AddForce(transform.forward * Slingshot_force * t, ForceMode.VelocityChange); // add force } else { rb.AddForce(transform.forward * Slingshot_force * relativeVelocityMax, ForceMode.VelocityChange); } if (Sfx_Hit) { sound_.PlayOneShot(Sfx_Hit); // Play a sound if needed } for (var j = 0; j < Parent_Manager.Length; j++) { Parent_Manager[j].SendMessage(functionToCall, index); // Call Parents Mission script } if (gameManager) { gameManager.F_Mode_BONUS_Counter(); // add one to the BONUS_Counter } if (gameManager) { gameManager.Add_Score(Points); // add points } if (obj_Led) { Led_Renderer.Led_On_With_Timer(.2f); // blinking } if (obj_Toy) { toy.PlayAnimationNumber(animNumber); // play animation } } }
void OnTriggerExit(Collider other) // --> When ball enter on the trigger { Lap++; //tmp_CheckLap = Lap; for (var j = 0; j < Parent_Manager.Length; j++) { Parent_Manager[j].SendMessage(functionToCall, index); // Call Parents Mission script } if (Sfx_Rotation) { sound_.PlayOneShot(Sfx_Rotation); // Play soiund if needed } if (gameManager) { gameManager.F_Mode_BONUS_Counter(); // Send Message to the gameManager(Manager_Game.js) Add 1 to BONUS_Global_Hit_Counter } if (gameManager) { gameManager.Add_Score(Points); // Send Message to the gameManager(Manager_Game.js) Add Points to Add_Score } }
void OnCollisionEnter(Collision collision) { if (collision.transform.tag == "Ball") { for (var j = 0; j < Parent_Manager.Length; j++) { Parent_Manager[j].SendMessage(functionToCall, index); // Call Parents Mission script } if (!sound_.isPlaying && Sfx_Hit) { sound_.PlayOneShot(Sfx_Hit); // Play a sound } if (gameManager) { gameManager.F_Mode_BONUS_Counter(); // Add Points to bonus counter } if (gameManager) { gameManager.Add_Score(Points); // Add point to score } } }
void OnCollisionEnter(Collision collision) // --> OnCollisionEnter { if (collision.transform.tag == "Ball" && rb == null) // OnCollisionEnter with a ball and There is no ball in the hole actualy { if (Mission_Kickback) { Box_Col.isTrigger = true; if (obj_Game_Manager != null) { if (gameManager) { gameManager.PlayMultiLeds(KickbackLedAnimation); // Choose Led ANimation if it's a kickback mission } } } tmp_Ball = collision.gameObject; rb = tmp_Ball.GetComponent <Rigidbody>(); rb.isKinematic = true; // rb become kinematic rb.position = transform.position; rb.rotation = Quaternion.identity; if (!sound_.isPlaying && Sfx_Load_Ball) { sound_.PlayOneShot(Sfx_Load_Ball); // Play sound : Sfx_Load_Ball } b_Part_1 = false; // start the first phase if (obj_Led) { led_Renderer.F_ChangeSprite_Off(); // switch off the led } if (Parent_Manager.Length > 0) { for (var j = 0; j < Parent_Manager.Length; j++) { Parent_Manager[j].SendMessage(functionToCall, index); // Call Parents Mission script } } if (obj_Game_Manager != null) { if (gameManager) { gameManager.F_Mode_BONUS_Counter(); // Add +1 to the Bonus counter. Manage by the Manager_Game game object on the hierarchy } if (gameManager) { gameManager.Add_Score(Points); // Add points. Manage by the Manager_Game game object on the hierarchy } } if (Toy_Enter) { toyEnter.PlayAnimationNumber(AnimNunEnter); // Play Toy if connected } if (MovingObjects && b_Open) { MovingObjects.openDoor(); } else if (MovingObjects && bClose) { MovingObjects.closeDoor(); } tmp_Ball.GetComponent <Ball>().OnHole(); // The ball is in the hole } }