/// <summary> /// Test distance to use pickup for AI /// </summary> bool InDistOfUseAI(PICKUPTYPE a_type, float a_dist) { bool res = true; switch (a_type) { case PICKUPTYPE.BOOST: res = a_dist > 1.5f; break; case PICKUPTYPE.LOW: res = a_dist < 2; break; } return(res); }
/// <summary> /// Determine if AI use is PickUp /// </summary> public void UsePickUpIA() { if (m_pickUp) { GameObject ball = GameManager.GetBallInfo(); float direction = ball.GetComponent <Rigidbody2D>().velocity.y; PICKUPTYPE acceptType = direction / transform.position.y > 0 ? PICKUPTYPE.LOW : PICKUPTYPE.BOOST; Vector2 ballPos = ball.transform.position; Vector2 pos = transform.position; if (m_pickUp.GetPickUpType() == acceptType && InDistOfUseAI(acceptType, Mathf.Abs(pos.y - ballPos.y))) { UsePickUp(); } } }