I really like the idea of the autoplay feature, and given I plan to push to around 100 levels or so, didn’t really want to have to keep firing the ball off.
I came up with a rather simple solution, which I thought I would share
After adding the flag to the Paddle script (inAutoPlay in my case), I simply added another check to the Ball scripts update method, as so:
// Update is called once per frame
void Update()
{
if (!hasStarted)
{
// Lock the ball relative to the paddle
this.transform.position = Paddle.transform.position + paddleToBallVector;
if (Input.GetMouseButtonDown(0) || Paddle.inAutoPlay)
{
fireBallOff();
}
}
}
and the fire ball method…
void fireBallOff()
{
hasStarted = true;
gameObject.GetComponent<Rigidbody2D>().velocity = new Vector2(2f, 10f);
}
Hopefully may help someone else.