// Start is called before the first frame update void Start() { inputData = InputController.Instance.GetInputData(InputController.PlayerControl.Player1); m_balloonLocomotion = m_balloonLocomotion == null?GetComponentInChildren <BalloonLocomotion>() : m_balloonLocomotion; m_balloonPhysicsController = m_balloonPhysicsController == null?GetComponentInChildren <BalloonPhysicsController>() : m_balloonPhysicsController; m_balloonFuel = m_balloonFuel == null?GetComponentInChildren <BalloonFuel>() : m_balloonFuel; m_balloonHealth = m_balloonHealth == null?GetComponentInChildren <BalloonHealth>() : m_balloonHealth; }
private void OnCollisionEnter2D(Collision2D collision) { Debug.Log(collision.gameObject); if (collision.collider.gameObject.layer == LayerMask.NameToLayer("Balloon")) { if (collision.gameObject.GetComponentInChildren <BalloonLocomotion>()) { BalloonLocomotion targetScript = collision.gameObject.GetComponentInChildren <BalloonLocomotion>(); BalloonHealth targetHealthScript = collision.gameObject.GetComponentInChildren <BalloonHealth>(); Vector2 impulseDirection = (targetScript.transform.position - transform.position).normalized; targetScript.ApplyBalloonImpulse(impulseDirection, 3f); targetHealthScript.Damage(1); } } }