Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Cannon : MonoBehaviour
- {
- public GameObject lavaRock;
- [SerializeField] public bool IsInstanciated;
- public PlayerController player;
- public int ballAmout = 3;
- public bool canShoot;
- public GameManager gameManager;
- private void Start()
- {
- canShoot = true;
- if (player != null)
- {
- player = FindObjectOfType<PlayerController>();
- }
- }
- private void Update()
- {
- if (!lavaRock.activeInHierarchy)
- {
- if (player != null)
- {
- StartCoroutine(SpawnLavaRock());
- }
- }
- }
- IEnumerator SpawnLavaRock()
- {
- if (canShoot)
- {
- if (Vector2.Distance(player.transform.position, this.transform.position) < 5)
- {
- if (!IsInstanciated)
- {
- IsInstanciated = true;
- ballAmout--;
- Instantiate(lavaRock, transform.position, Quaternion.identity);
- yield return new WaitForSeconds(1f);
- IsInstanciated = false;
- }
- }
- }
- if(ballAmout <= 0)
- {
- canShoot= false;
- StopCoroutine(SpawnLavaRock());
- gameManager.EndGame();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement