using System.Collections; using System.Collections.Generic; using UnityEngine; public class GameController : MonoBehaviour{ public bool spawnEnemies = true; public Pool poolToCreate; public Vector3 whereToSpawn; public float spawnRate; [Header("Game Over")] public bool gameOver; public GameObject gameOverScreen; [Header("Win")] public bool win; public GameObject winScreen; public HumoLookAt humo; public Transform humoSpawn; GameObject player; public GameObject casa; public GameObject target; public GameObject[] casas; EnemyController[] enemies; [HideInInspector] public bool readyToSpawn = false; bool spawnHumo; bool brujula; float nextSpawn; public LightBar lightBar; void Awake(){ Pooler.CreatePools(poolToCreate); } // Start is called before the first frame update void Start(){ Invoke(nameof(ReadyToSpawn), 2); player = GameObject.FindGameObjectWithTag("Player"); if (!PlayerPrefs.HasKey("CheckPoint")){ int intCasa = Random.Range(0, casas.Length - 1); casa.transform.position = casas[intCasa].transform.position; casa.transform.rotation = casas[intCasa].transform.rotation; casa.SetActive(true); PlayerPrefs.SetInt("Casa", intCasa); }else{ casa.transform.position = casas[PlayerPrefs.GetInt("Casa")].transform.position; casa.transform.rotation = casas[PlayerPrefs.GetInt("Casa")].transform.rotation; casas[PlayerPrefs.GetInt("Casa")].SetActive(false); casa.SetActive(true); } AudioManager.instance.Play("Theme"); AudioManager.instance.PlayMuted("Theme2"); AudioManager.instance.Play("Vela"); AudioManager.instance.Stop("Menu"); enemies = GameObject.FindObjectsOfType(); } // Update is called once per frame void Update(){ Vector2 bruj = casa.transform.position - player.transform.position; float rot = Mathf.Atan2(bruj.y, bruj.x) * Mathf.Rad2Deg; humo.t = Quaternion.Euler(humo.transform.rotation.x, humo.transform.rotation.y, rot - 90); //target = new Vector3(closestEnemy.transform.position.x, closestEnemy.transform.position.y, closestEnemy.transform.position.z); Debug.DrawLine(player.transform.position, casa.transform.position); if (readyToSpawn){ if (Time.time > nextSpawn){ if (spawnEnemies){ nextSpawn = Time.time + spawnRate; float xPos = Random.Range(player.transform.position.x - 40f, player.transform.position.x + 40f); float yPos = Random.Range(player.transform.position.y - 40f, player.transform.position.y + 40f); whereToSpawn = new Vector3(xPos, yPos, 0f); Pooler.SpawnFromPool("Enemies", whereToSpawn, Quaternion.identity); } if (Input.GetButtonDown("Fire")){ if (brujula){ spawnHumo = false; brujula = false; }else{ spawnHumo = true; brujula = true; } } if (spawnHumo){ Pooler.SpawnFromPool("Humo", humoSpawn.position, Quaternion.identity, humo.transform); } } } if (win){ winScreen.SetActive(true); Time.timeScale = 0; } if (gameOver){ gameOverScreen.SetActive(true); } } void ReadyToSpawn(){ readyToSpawn = true; } }