private void OnTriggerEnter2D(Collider2D collision) { cFallingObject OTHER = collision.GetComponent <cFallingObject>(); if (OTHER == null) { return; } else if (OTHER.tag == "Crook" || OTHER.tag == "Civilian") { Rigidbody2D OTHER_RIGIDBODY = OTHER.GetComponent <Rigidbody2D>(); if (OTHER_RIGIDBODY.velocity.y > 0) { return; } // Depending on the trampoline's tilt direction, set velocity so the objective goes either to the SWAT or Ambulance float NEW_VELOCITY_X; float NEW_VELOCITY_Y = Mathf.Abs(OTHER_RIGIDBODY.velocity.y) * UnityEngine.Random.Range(0.7f, 0.8f); if (tiltDirection == enumDirection.Left) { NEW_VELOCITY_X = -(swat.transform.position.x - OTHER.transform.position.x) / (NEW_VELOCITY_Y / Physics2D.gravity.y); OTHER_RIGIDBODY.angularVelocity += UnityEngine.Random.Range(90f, 180f); } else { NEW_VELOCITY_X = -(ambulance.transform.position.x - OTHER.transform.position.x) / (NEW_VELOCITY_Y / Physics2D.gravity.y); OTHER_RIGIDBODY.angularVelocity -= UnityEngine.Random.Range(90f, 180f); } OTHER_RIGIDBODY.velocity = new Vector2(NEW_VELOCITY_X * 0.5f, NEW_VELOCITY_Y); } }
private void OnTriggerEnter2D(Collider2D collision) { cFallingObject OTHER = collision.GetComponent <cFallingObject>(); if (OTHER == null) { return; } else if (OTHER.tag == "Crook") { scoreKeeper.GainScore(1); } else //if ( OTHER.tag == "Civilian" ) { // Play sound here { player.FailedObjective(); } Destroy(OTHER.gameObject); }