1
Fork 0
mirror of https://github.com/Steffo99/bleach-beach.git synced 2024-12-04 19:04:19 +00:00
bleach-beach/Assets/Scripts/FishSpawnerEnding.cs
2018-08-13 19:33:58 +02:00

51 lines
1.4 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class FishSpawnerEnding : MonoBehaviour
{
public float spawnTime = 5f;
public float randomFactor = 1f;
public GameObject fish;
public GameObject sea;
public Text punteggio;
public Text winner;
private float timeToSpawn;
private int toSpawn;
private int spawned = 0;
private string vincitore = "";
void Start()
{
timeToSpawn = Random.Range(spawnTime - randomFactor, spawnTime + randomFactor);
toSpawn = PlayerPrefs.GetInt("player_score");
vincitore = PlayerPrefs.GetString("winner");
}
void Update()
{
timeToSpawn -= Time.deltaTime;
if (timeToSpawn <= 0 && spawned < toSpawn)
{
GameObject newFish = Instantiate(fish);
newFish.transform.position = transform.position;
newFish.GetComponent<FishAi>().sea = sea;
timeToSpawn = Random.Range(spawnTime - randomFactor, spawnTime + randomFactor);
spawned++;
punteggio.text = spawned.ToString() + " fish";
}
if (spawned >= toSpawn)
{
if(vincitore == "Player")
{
winner.text = "You win!";
}
else if(vincitore == "AI")
{
winner.text = "The bots win!";
}
}
}
}