Hi all,
I have just finished up the Block Breaker section of the course, and I wanted to add a life system to my game. I mostly understood what was going on when following the course, but its much harder when you are on your own!
Anyway, I have managed to add the life system to the game, but what I am having trouble with is resetting the ball to the paddle. So far in my LoseCollider.cs script, I have this:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class LoseCollider : MonoBehaviour
{
public int playerLives = 3;
public Ball ball;
public Paddle paddle;
public Vector2 paddleToBallVector;
private void OnTriggerEnter2D(Collider2D collision)
{
playerLives--;
if (playerLives > 0)
{
ball = GameObject.FindObjectOfType<Ball>();
paddle = GameObject.FindObjectOfType<Paddle>();
ball.transform.position = new Vector3(paddle.transform.position.x, 1.343f);
}
else if (playerLives <= 0)
{
SceneManager.LoadScene("End Game");
}
}
}
my initial thoughts were adding “Ball.hasStarted = False” within the private void OnTriggerEnter2D(Collider2D collision) section, but the hasStarted is underlined in red with the error “Ball.hasStarted” is inaccessible due to its protection level.
Anyone able to point out where im going wrong and tell me how I can reset the ball to the paddle!
Thanks in advance.