Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //script reference
- [SerializeField] GameObject spawner;
- [SerializeField] MovePlayer movePlayer;
- [SerializeField] AudioClip winningSFX;
- // cache references
- [SerializeField] int ballsLeft;
- [SerializeField] int livesLeft = 3;
- [SerializeField] GameObject livesImg;
- [SerializeField] GameObject livesImg2;
- [SerializeField] GameObject livesImg3;
- [SerializeField] GameObject livesImg4;
- [SerializeField] GameObject livesImg5;
- [SerializeField] GameObject winScreen;
- [SerializeField] GameObject loseScreen;
- [SerializeField] TextMeshProUGUI ballsLeftText;
- [SerializeField] GameObject spawnerParent;
- [SerializeField] GameObject spawnerParent2;
- [SerializeField] GameObject spawnerParent3;
- // Start is called before the first frame update
- void Start()
- {
- var movePlayer = FindObjectsOfType<MovePlayer>();
- loseScreen.SetActive(false);
- winScreen.SetActive(false);
- }
- // Update is called once per frame
- void Update()
- {
- ballsLeftText.text = "Balls Left: " + ballsLeft;
- }
- public void CatchBall()
- {
- ballsLeft -= 1;
- if(ballsLeft < 0)
- {
- ballsLeft = 0;
- }
- if (ballsLeft == 0)
- {
- Destroy(spawnerParent);
- Destroy(spawnerParent2);
- Destroy(spawnerParent3);
- DisplayWinScreen();
- movePlayer.enabled = false;
- }
- }
- public void LoseLife()
- {
- livesLeft -= 1;
- if(livesLeft == 4)
- {
- livesImg5.gameObject.SetActive(false);
- }
- if (livesLeft == 3)
- {
- livesImg4.gameObject.SetActive(false);
- }
- if (livesLeft == 2)
- {
- livesImg3.gameObject.SetActive(false);
- }
- else if(livesLeft == 1)
- {
- livesImg2.gameObject.SetActive(false);
- }
- else if(livesLeft == 0)
- {
- Destroy(livesImg);
- Destroy(spawnerParent);
- Destroy(spawnerParent2);
- Destroy(spawnerParent3);
- movePlayer.enabled = false;
- DisplayLoseScreen();
- }
- else if(livesLeft <= 0)
- {
- livesLeft = 0;
- }
- }
- public void AddLife()
- {
- Debug.Log(livesLeft);
- livesLeft += 1;
- Debug.Log(livesLeft);
- }
- private void DisplayLoseScreen()
- {
- loseScreen.SetActive(true);
- }
- private void DisplayWinScreen()
- {
- AudioSource.PlayClipAtPoint(winningSFX, Camera.main.transform.position);
- winScreen.SetActive(true);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement