So I am making a level with two paddles, however I only want each paddle to work if the mouse is within a certain distance from the object. I am struggling on how to do this.
public class Paddle : MonoBehaviour
{
[SerializeField] float screenWidthInUnits = 16f;
[SerializeField] float minX = 1f;
[SerializeField] float maxX = 13.5f;
[SerializeField] int numberOfPaddles;
public float distancePaddleCanWork = 4f;
//cached ref
GameStatus theGameStatus;
Rocket theRocket;
// Start is called before the first frame update
void Start()
{
theGameStatus = FindObjectOfType<GameStatus>();
theRocket = FindObjectOfType<Rocket>();
}
// Update is called once per frame
void Update()
{
Vector2 paddlePos = new Vector2(transform.position.x, transform.position.y);
if (numberOfPaddles > 1)
{
if(distancePaddleCanWork = transform.position -Input.mousePosition)
}
else
{
paddlePos.x = Mathf.Clamp(GetXPos(), minX, maxX);
transform.position = paddlePos;
}
}
private float GetXPos()
{
if (theGameStatus.IsAutoPlayEnabled())
{
return theRocket.transform.position.x;
}
else
{
return Input.mousePosition.x / Screen.width * screenWidthInUnits;
}
}
}