Archivo inicial.
This commit is contained in:
@@ -0,0 +1,261 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class BoatManager : MonoBehaviour
|
||||
{
|
||||
|
||||
//float duration = 50;
|
||||
public GameObject boat;
|
||||
|
||||
[Header("GameVars Spawn")]
|
||||
public bool automatic;
|
||||
public float spawnDelay;
|
||||
public float minSpawnDelay;
|
||||
public float decrementBetweenSpawns;
|
||||
|
||||
[Header("GameVars Boat")]
|
||||
public float minBoatSpeed;
|
||||
public float maxBoatSpeed;
|
||||
|
||||
|
||||
[Header("Probs")]
|
||||
public float narcoProb;
|
||||
public float loopProb;
|
||||
|
||||
|
||||
[Header("Sprites")]
|
||||
public Sprite[] boatSprites = new Sprite[4];
|
||||
public Sprite[] destuidosBoatsSprites = new Sprite[4];
|
||||
|
||||
|
||||
[Header("AreaMar")]
|
||||
public float maxMarY;
|
||||
public float minMarY;
|
||||
public float maxMarX;
|
||||
public float minMarX;
|
||||
|
||||
[Header("AreaTerra")]
|
||||
public float maxTerraY;
|
||||
public float minTerraY;
|
||||
public float maxTerraX;
|
||||
public float minTerraX;
|
||||
|
||||
|
||||
enum barcosSprites
|
||||
{
|
||||
narcoBarco = 0, civil1 = 1, civil2 = 2, civil3 = 3
|
||||
}
|
||||
|
||||
|
||||
|
||||
BoatMov bm;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
bm = boat.GetComponent<BoatMov>();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.G))
|
||||
{
|
||||
GenerateBoat();
|
||||
}
|
||||
}
|
||||
|
||||
public void StartBoatGen()
|
||||
{
|
||||
if (automatic)
|
||||
{
|
||||
GenerateBoat();
|
||||
GenerateBoat();
|
||||
GenerateBoat();
|
||||
|
||||
StartCoroutine("Spawn");
|
||||
}
|
||||
}
|
||||
|
||||
public void StopBoarGen()
|
||||
{
|
||||
if (automatic)
|
||||
{
|
||||
StopCoroutine("Spawn");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void GenerateBoat()
|
||||
{
|
||||
bm.defaultSpeed = Random.Range(minBoatSpeed, maxBoatSpeed);
|
||||
|
||||
bm.isNarco = RandBool(narcoProb);
|
||||
|
||||
if (!bm.isNarco)
|
||||
{
|
||||
int i = Mathf.RoundToInt(Random.Range(1, 3.4f));
|
||||
bm.gameObject.GetComponent<SpriteRenderer>().sprite = boatSprites[i];
|
||||
bm.destroyedSprite = destuidosBoatsSprites[i];
|
||||
|
||||
bm.routeLoop = RandBool(loopProb);
|
||||
}else if (bm.isNarco)
|
||||
{
|
||||
bm.gameObject.GetComponent<SpriteRenderer>().sprite = boatSprites[(int)barcosSprites.narcoBarco];
|
||||
bm.destroyedSprite = destuidosBoatsSprites[(int)barcosSprites.narcoBarco];
|
||||
|
||||
bm.routeLoop = false;
|
||||
}
|
||||
|
||||
//Start Pos.
|
||||
Vector2 pos = GenOutPos(Areas.Mar);
|
||||
bm.transform.position = pos;
|
||||
|
||||
//Route pos.
|
||||
if (bm.routeLoop)
|
||||
{
|
||||
for (int i = 0; i < bm.route.Length; i++)
|
||||
{
|
||||
Vector3 routePos = new Vector3(Random.Range(minMarX, maxMarX), Random.Range(minMarY, maxMarY), 0);
|
||||
bm.route[i] = routePos;
|
||||
}
|
||||
}
|
||||
else if (!bm.routeLoop)
|
||||
{
|
||||
for (int i = 0; i < bm.route.Length - 1; i++)
|
||||
{
|
||||
Vector3 routePos = GenInsidePos(Areas.Mar);
|
||||
bm.route[i] = routePos;
|
||||
}
|
||||
Vector3 routePosEnd = GenOutPos(Areas.Mar);
|
||||
bm.route[bm.route.Length - 1] = routePosEnd;
|
||||
|
||||
if (bm.isNarco)
|
||||
{
|
||||
bm.route[bm.route.Length - 2] = GenInsidePos(Areas.tierra);
|
||||
}
|
||||
}
|
||||
|
||||
Instantiate(boat, gameObject.transform, true);
|
||||
}
|
||||
|
||||
|
||||
#region VectorGen
|
||||
|
||||
public enum Areas
|
||||
{
|
||||
Mar = 0, tierra = 1
|
||||
}
|
||||
|
||||
public Vector3 GenInsidePos(Areas area)
|
||||
{
|
||||
float minX = 0, minY = 0, maxX = 0, maxY = 0;
|
||||
if (area.Equals(Areas.Mar))
|
||||
{
|
||||
minX = minMarX; minY = minMarY; maxX = maxMarX; maxY = maxMarY;
|
||||
}
|
||||
else if (area.Equals(Areas.tierra))
|
||||
{
|
||||
minX = minTerraX; minY = minTerraY; maxX = maxTerraX; maxY = maxTerraY;
|
||||
}
|
||||
|
||||
Vector2 pos = new Vector2(Random.Range(minX, maxX), Random.Range(minY, maxY));
|
||||
return pos;
|
||||
|
||||
}
|
||||
|
||||
public Vector2 GenOutPos(Areas area)
|
||||
{
|
||||
float minX = 0, minY = 0, maxX = 0, maxY = 0;
|
||||
if(area.Equals(Areas.Mar))
|
||||
{
|
||||
minX = minMarX; minY = minMarY; maxX = maxMarX; maxY = maxMarY;
|
||||
}else if (area.Equals(Areas.tierra))
|
||||
{
|
||||
minX = minTerraX; minY = minTerraY; maxX = maxTerraX; maxY = maxTerraY;
|
||||
}
|
||||
|
||||
Vector2 pos = new Vector2();
|
||||
int j = Mathf.RoundToInt(Random.Range(1.0f, 3.5f));
|
||||
switch (j)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
pos = new Vector2(minX, Random.Range(minY, maxY));
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
pos = new Vector2(Random.Range(minX, maxX), maxY);
|
||||
break;
|
||||
}
|
||||
case 3:
|
||||
{
|
||||
pos = new Vector2(maxX, Random.Range(minY, maxY));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
Debug.LogError("Can't Gen");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Coroutines
|
||||
|
||||
IEnumerator Spawn()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
GenerateBoat();
|
||||
|
||||
yield return new WaitForSeconds(spawnDelay);
|
||||
|
||||
if(spawnDelay > minSpawnDelay)
|
||||
{
|
||||
spawnDelay -= decrementBetweenSpawns;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
public bool RandBool(float probability)
|
||||
{
|
||||
if(Random.value < probability)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void OnDrawGizmosSelected()
|
||||
{
|
||||
Gizmos.color = Color.cyan;
|
||||
Gizmos.DrawLine(new Vector3(minMarX, minMarY), new Vector3(minMarX, maxMarY));
|
||||
Gizmos.DrawLine(new Vector3(minMarX, maxMarY), new Vector3(maxMarX, maxMarY));
|
||||
Gizmos.DrawLine(new Vector3(maxMarX, maxMarY), new Vector3(maxMarX, minMarY));
|
||||
Gizmos.DrawLine(new Vector3(maxMarX, minMarY), new Vector3(minMarX, minMarY));
|
||||
|
||||
Gizmos.color = Color.magenta;
|
||||
Gizmos.DrawLine(new Vector3(minTerraX, minTerraY), new Vector3(minTerraX, maxTerraY));
|
||||
Gizmos.DrawLine(new Vector3(minTerraX, maxTerraY), new Vector3(maxTerraX, maxTerraY));
|
||||
Gizmos.DrawLine(new Vector3(maxTerraX, maxTerraY), new Vector3(maxTerraX, minTerraY));
|
||||
Gizmos.DrawLine(new Vector3(maxTerraX, minTerraY), new Vector3(minTerraX, minTerraY));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9cf55e78f33cfda4aa36d92459c6bbb4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,361 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class BoatMov : MonoBehaviour
|
||||
{
|
||||
|
||||
GameManager GM;
|
||||
Rigidbody2D rb;
|
||||
Camera cam;
|
||||
|
||||
PlayerMov player;
|
||||
|
||||
GameObject OverlayPanel;
|
||||
GameObject bar;
|
||||
public SpriteRenderer estadoSprite;
|
||||
|
||||
[Header("Visual")]
|
||||
public GameObject progessBarPref;
|
||||
public Sprite destroyedSprite;
|
||||
public Sprite narcoSprite;
|
||||
public Sprite salvarSprite;
|
||||
public Sprite arrestarSprite;
|
||||
public Sprite descargandoSprite;
|
||||
public Sprite voidSprite;
|
||||
|
||||
|
||||
bool hundiendo = false;
|
||||
bool interactuando = false;
|
||||
bool traficando = false;
|
||||
bool traficado = false;
|
||||
bool OnArea = false;
|
||||
|
||||
[Header("IsIt")]
|
||||
public bool isNarco = false;
|
||||
|
||||
|
||||
int boatCargo = 1;
|
||||
|
||||
|
||||
[Header("GameVars")]
|
||||
public float deathTime = 5;
|
||||
public float interactTime = 5;
|
||||
public float traficarTime = 5;
|
||||
public float speed = 1f;
|
||||
public float defaultSpeed = 4f;
|
||||
public float rotSmooth = 5f;
|
||||
public Vector3[] route;
|
||||
public bool routeLoop = false;
|
||||
int currentPoint = 1;
|
||||
|
||||
float dTime;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
route[0] = transform.position;
|
||||
rb = GetComponent<Rigidbody2D>();
|
||||
GM = GameObject.FindGameObjectWithTag("GM").GetComponent<GameManager>();
|
||||
cam = GameObject.FindGameObjectWithTag("MainCamera").GetComponent<Camera>();
|
||||
OverlayPanel = GameObject.FindGameObjectWithTag("Canvas");
|
||||
player = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerMov>();
|
||||
|
||||
bar = Instantiate(progessBarPref, OverlayPanel.transform, false);
|
||||
|
||||
|
||||
bar.SetActive(false);
|
||||
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (isNarco)
|
||||
{
|
||||
estadoSprite.sprite = narcoSprite;
|
||||
}
|
||||
|
||||
speed = defaultSpeed;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
#region BoatMov.
|
||||
if (GM.playing)
|
||||
{
|
||||
|
||||
Vector3 mov = route[currentPoint] - transform.position;
|
||||
|
||||
float angle = Vector2.SignedAngle(new Vector2(1, 0), new Vector2(mov.x, mov.y));
|
||||
|
||||
Quaternion target = Quaternion.Euler(0, 0, angle);
|
||||
transform.rotation = Quaternion.Slerp(transform.rotation, target, Time.deltaTime * rotSmooth * Time.timeScale);
|
||||
|
||||
if (mov.magnitude < 1f)
|
||||
{
|
||||
if (currentPoint < route.Length - 1)
|
||||
{
|
||||
currentPoint++;
|
||||
}
|
||||
else if (currentPoint == route.Length - 1)
|
||||
{
|
||||
if (routeLoop)
|
||||
{
|
||||
currentPoint = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isNarco)
|
||||
{
|
||||
GM.AddNarcoHuido(boatCargo);
|
||||
}
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mov.Normalize();
|
||||
transform.position = transform.position + mov * speed * Time.timeScale * Time.deltaTime;
|
||||
|
||||
|
||||
Vector3 screenPto = cam.WorldToScreenPoint(transform.position);
|
||||
bar.transform.position = screenPto;
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
if (interactuando)
|
||||
{
|
||||
bar.GetComponent<Slider>().value = ((Time.time - dTime) / interactTime);
|
||||
player.SetPlayerSpeed(0);
|
||||
speed = 0;
|
||||
}
|
||||
|
||||
else if (!interactuando)
|
||||
{
|
||||
if (hundiendo)
|
||||
{
|
||||
bar.GetComponent<Slider>().value = ((Time.time - dTime) / deathTime);
|
||||
|
||||
if(OnArea && Input.GetKeyDown(KeyCode.F) && !isNarco)
|
||||
{
|
||||
Rescate();
|
||||
}
|
||||
|
||||
if(bar.GetComponent<Slider>().value >= 1)
|
||||
{
|
||||
Destroy(bar);
|
||||
Destroy(gameObject);
|
||||
|
||||
GM.AddNaufMuerto(boatCargo);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (isNarco && OnArea && Input.GetKeyDown(KeyCode.F))
|
||||
{
|
||||
Arresto();
|
||||
}
|
||||
|
||||
if (traficando)
|
||||
{
|
||||
bar.GetComponent<Slider>().value = ((Time.time - dTime) / traficarTime);
|
||||
|
||||
if (bar.GetComponent<Slider>().value >= 1)
|
||||
{
|
||||
traficando = false;
|
||||
traficado = true;
|
||||
currentPoint += 1;
|
||||
speed = defaultSpeed;
|
||||
bar.SetActive(false);
|
||||
}
|
||||
if (OnArea)
|
||||
{
|
||||
estadoSprite.sprite = arrestarSprite;
|
||||
}
|
||||
else
|
||||
{
|
||||
estadoSprite.sprite = descargandoSprite;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
private void OnDestroy()
|
||||
{
|
||||
player.ResetPlayerSpeed();
|
||||
}
|
||||
|
||||
private void OnCollisionEnter2D(Collision2D collision)
|
||||
{
|
||||
if (!hundiendo && collision.gameObject.tag == "Player")
|
||||
{
|
||||
GM.bossAnger += GM.angerPerDestroyBoat;
|
||||
Destroy();
|
||||
}
|
||||
|
||||
if (!hundiendo && collision.gameObject.tag != "Tierra")
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
if (!traficado && collision.gameObject.tag == "Tierra" && isNarco)
|
||||
{
|
||||
Traficar();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D collision)
|
||||
{
|
||||
if(collision.gameObject.tag == "Player")
|
||||
{
|
||||
if (isNarco)
|
||||
{
|
||||
estadoSprite.sprite = arrestarSprite;
|
||||
}else if (hundiendo)
|
||||
{
|
||||
estadoSprite.sprite = salvarSprite;
|
||||
}
|
||||
OnArea = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTriggerStay2D(Collider2D collision)
|
||||
{
|
||||
if (!OnArea && collision.gameObject.tag == "Player")
|
||||
{
|
||||
if (isNarco)
|
||||
{
|
||||
estadoSprite.sprite = arrestarSprite;
|
||||
}else if (hundiendo)
|
||||
{
|
||||
estadoSprite.sprite = salvarSprite;
|
||||
}
|
||||
OnArea = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTriggerExit2D(Collider2D collision)
|
||||
{
|
||||
if(OnArea && collision.gameObject.tag == "Player")
|
||||
{
|
||||
if (isNarco)
|
||||
{
|
||||
estadoSprite.sprite = narcoSprite;
|
||||
}
|
||||
else
|
||||
{
|
||||
estadoSprite.sprite = voidSprite;
|
||||
}
|
||||
OnArea = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void Destroy()
|
||||
{
|
||||
dTime = Time.time;
|
||||
hundiendo = true;
|
||||
gameObject.GetComponent<SpriteRenderer>().sprite = destroyedSprite;
|
||||
speed = 0;
|
||||
rb.constraints = RigidbodyConstraints2D.FreezeAll;
|
||||
bar.GetComponent<Slider>().value = 0;
|
||||
bar.SetActive(true);
|
||||
GM.PlaySoundEffect(GameManager.soundEffects.accidenteBarco);
|
||||
}
|
||||
|
||||
private void Rescate()
|
||||
{
|
||||
if (!player.IsFullCarga())
|
||||
{
|
||||
Debug.Log("Rescate");
|
||||
|
||||
dTime = Time.time;
|
||||
Destroy(bar, interactTime);
|
||||
Destroy(gameObject, interactTime);
|
||||
|
||||
player.AddCargo(PlayerMov.CargoType.nauf, boatCargo);
|
||||
speed = 0;
|
||||
|
||||
bar.SetActive(true);
|
||||
bar.GetComponent<Slider>().value = 0;
|
||||
player.SetPlayerSpeed(0);
|
||||
|
||||
interactuando = true;
|
||||
GM.PlaySoundEffect(GameManager.soundEffects.rescateBarco);
|
||||
}
|
||||
else
|
||||
{
|
||||
player.SetLlenoSprite();
|
||||
GM.PlaySoundEffect(GameManager.soundEffects.fullCarga);
|
||||
}
|
||||
}
|
||||
|
||||
private void Arresto()
|
||||
{
|
||||
if (!player.IsFullCarga())
|
||||
{
|
||||
|
||||
Debug.Log("Arresto");
|
||||
|
||||
dTime = Time.time;
|
||||
Destroy(bar, interactTime);
|
||||
Destroy(gameObject, interactTime);
|
||||
|
||||
player.AddCargo(PlayerMov.CargoType.narcos, boatCargo);
|
||||
|
||||
speed = 0;
|
||||
|
||||
bar.SetActive(true);
|
||||
bar.GetComponent<Slider>().value = 0;
|
||||
player.SetPlayerSpeed(0);
|
||||
|
||||
interactuando = true;
|
||||
GM.PlaySoundEffect(GameManager.soundEffects.detencionNarco);
|
||||
}
|
||||
else
|
||||
{
|
||||
player.SetLlenoSprite();
|
||||
GM.PlaySoundEffect(GameManager.soundEffects.fullCarga);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void Traficar()
|
||||
{
|
||||
Debug.Log("Traficando");
|
||||
|
||||
dTime = Time.time;
|
||||
|
||||
speed = 0;
|
||||
|
||||
bar.SetActive(true);
|
||||
bar.GetComponent<Slider>().value = 0;
|
||||
estadoSprite.sprite = descargandoSprite;
|
||||
traficando = true;
|
||||
GM.PlaySoundEffect(GameManager.soundEffects.narcoTraficando);
|
||||
}
|
||||
|
||||
private void OnDrawGizmosSelected()
|
||||
{
|
||||
route[0] = transform.position;
|
||||
for (int i = 0; i < route.Length; i++)
|
||||
{
|
||||
Gizmos.DrawWireSphere(route[i], 0.3f);
|
||||
if (i < route.Length - 1)
|
||||
{
|
||||
Gizmos.DrawLine(route[i], route[i + 1]);
|
||||
}
|
||||
}
|
||||
if (routeLoop)
|
||||
{
|
||||
Gizmos.DrawLine(route[route.Length-1], route[0]);
|
||||
}
|
||||
|
||||
Gizmos.color = Color.red;
|
||||
Gizmos.DrawLine(Vector2.zero, transform.position);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4a4e6d308180bd847a204a04cbb66b9a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,21 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public static class DataSave
|
||||
{
|
||||
public static float musicVol = 100;
|
||||
public static float effectsVol = 100;
|
||||
|
||||
|
||||
|
||||
public static int rescatados = 0;
|
||||
public static int detenidos = 0;
|
||||
public static int huidos = 0;
|
||||
public static int muertos = 0;
|
||||
|
||||
public static float gameTime = 0;
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b3762319573340a4aaef493edc85f4ac
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,262 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.Audio;
|
||||
|
||||
public class GameManager : MonoBehaviour
|
||||
{
|
||||
BoatManager BM;
|
||||
PlayerMov player;
|
||||
GameUIManager GUIM;
|
||||
|
||||
float startTime;
|
||||
float gameDuration;
|
||||
|
||||
public bool playing = false;
|
||||
public bool pause = false;
|
||||
|
||||
[Header("GameVars")]
|
||||
public int moneyPerPerson;
|
||||
[SerializeField]
|
||||
public int money = 0;
|
||||
|
||||
|
||||
[Header("InGameVars")]
|
||||
int naufResc;
|
||||
int naufMuertos;
|
||||
|
||||
int narcosDeten;
|
||||
int narcosHuidos;
|
||||
|
||||
[SerializeField]
|
||||
public float bossAnger = 0;
|
||||
[SerializeField]
|
||||
float angerPerMuerto = 0.1f;
|
||||
[SerializeField]
|
||||
float angerPerHuido = 0.1f;
|
||||
public float angerPerDestroyBoat = 0.1f;
|
||||
|
||||
[Header("InGameGUI")]
|
||||
public GameObject pauseMenu;
|
||||
|
||||
|
||||
public Slider angerBar;
|
||||
public TMPro.TMP_Text dineroText;
|
||||
|
||||
public Slider cargoBar;
|
||||
public TMPro.TMP_Text totalCargoText;
|
||||
public TMPro.TMP_Text narcoCargoText;
|
||||
public TMPro.TMP_Text naufCargoText;
|
||||
|
||||
[Header("Music&Sounds")]
|
||||
public AudioSource musicSource;
|
||||
public AudioSource effectsSource;
|
||||
[SerializeField]
|
||||
AudioClip[] soundEffectsClips = new AudioClip[5];
|
||||
|
||||
|
||||
public enum soundEffects
|
||||
{
|
||||
accidenteBarco = 0, rescateBarco = 1, detencionNarco = 2, naufragoMuerto = 3,
|
||||
narcoHuido = 4, descargaPuerto = 5, fullCarga = 6, narcoTraficando = 7, powerup = 8, select = 9
|
||||
}
|
||||
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Time.timeScale = 0;
|
||||
player = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerMov>();
|
||||
BM = GameObject.FindGameObjectWithTag("BM").GetComponent<BoatManager>();
|
||||
GUIM = GameObject.FindGameObjectWithTag("GUIM").GetComponent<GameUIManager>();
|
||||
|
||||
musicSource.volume = DataSave.musicVol;
|
||||
effectsSource.volume = DataSave.effectsVol;
|
||||
|
||||
musicSource.Play();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
UpdateTexts();
|
||||
angerBar.value = 0;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
|
||||
if(bossAnger >= 1)
|
||||
{
|
||||
EndGame();
|
||||
}
|
||||
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.D))
|
||||
{
|
||||
Debug.LogWarning("Rescatados: " + naufResc);
|
||||
Debug.LogWarning("Detenidos: " + narcosDeten);
|
||||
Debug.LogWarning("Huidos: " + narcosHuidos);
|
||||
Debug.LogWarning("Muertos: " + naufMuertos);
|
||||
}
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.A))
|
||||
{
|
||||
bossAnger += 0.2f;
|
||||
AngerBarUpdate();
|
||||
}
|
||||
|
||||
if (!pause && Input.GetKeyDown(KeyCode.Escape))
|
||||
{
|
||||
PauseGame();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
UpdateTexts();
|
||||
UpdateCargoBar();
|
||||
}
|
||||
|
||||
|
||||
public void StartGame()
|
||||
{
|
||||
if(!playing)
|
||||
{
|
||||
GUIM.InGameUI();
|
||||
startTime = Time.time;
|
||||
|
||||
Time.timeScale = 1;
|
||||
player.destPto = Vector3.zero;
|
||||
|
||||
playing = true;
|
||||
|
||||
BM.StartBoatGen();
|
||||
|
||||
AngerBarUpdate();
|
||||
StartCoroutine("AngerDown");
|
||||
}
|
||||
}
|
||||
|
||||
#region GameManagment
|
||||
|
||||
private void EndGame()
|
||||
{
|
||||
|
||||
Time.timeScale = 0;
|
||||
playing = false;
|
||||
gameDuration = Time.time - startTime;
|
||||
StopCoroutine("AngerDown");
|
||||
|
||||
SaveData();
|
||||
|
||||
BM.StopBoarGen();
|
||||
|
||||
GUIM.EndGameUI();
|
||||
|
||||
}
|
||||
|
||||
private void PauseGame()
|
||||
{
|
||||
pause = true;
|
||||
Time.timeScale = 0;
|
||||
pauseMenu.SetActive(true);
|
||||
}
|
||||
|
||||
public void ResumeGame()
|
||||
{
|
||||
UpdateTexts();
|
||||
pauseMenu.SetActive(false);
|
||||
pause = false;
|
||||
Time.timeScale = 1;
|
||||
}
|
||||
#endregion
|
||||
|
||||
public void DescargaPuerto(PlayerMov.CargoType type, int amount)
|
||||
{
|
||||
if (type == PlayerMov.CargoType.narcos)
|
||||
{
|
||||
narcosDeten += amount;
|
||||
}
|
||||
else if (type == PlayerMov.CargoType.nauf)
|
||||
{
|
||||
naufResc += amount;
|
||||
}
|
||||
money += amount * moneyPerPerson;
|
||||
PlaySoundEffect(soundEffects.descargaPuerto);
|
||||
}
|
||||
|
||||
public void AddNaufMuerto(int amount)
|
||||
{
|
||||
naufMuertos += amount;
|
||||
bossAnger += angerPerMuerto;
|
||||
AngerBarUpdate();
|
||||
PlaySoundEffect(soundEffects.naufragoMuerto);
|
||||
}
|
||||
public void AddNarcoHuido(int amount)
|
||||
{
|
||||
narcosHuidos += amount;
|
||||
bossAnger += angerPerHuido;
|
||||
AngerBarUpdate();
|
||||
PlaySoundEffect(soundEffects.narcoHuido);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void SaveData()
|
||||
{
|
||||
DataSave.rescatados = naufResc;
|
||||
DataSave.muertos = naufMuertos;
|
||||
|
||||
DataSave.detenidos = narcosDeten;
|
||||
DataSave.huidos = narcosHuidos;
|
||||
|
||||
DataSave.gameTime = gameDuration;
|
||||
|
||||
}
|
||||
|
||||
public void PlaySoundEffect(soundEffects type)
|
||||
{
|
||||
effectsSource.PlayOneShot(soundEffectsClips[(int)type]);
|
||||
}
|
||||
|
||||
#region UI
|
||||
|
||||
private void AngerBarUpdate()
|
||||
{
|
||||
angerBar.value = bossAnger;
|
||||
}
|
||||
|
||||
public void UpdateCargoBar()
|
||||
{
|
||||
cargoBar.value = player.totalCarga / player.maxCargo;
|
||||
}
|
||||
|
||||
public void UpdateTexts()
|
||||
{
|
||||
dineroText.text = "Money: " + money;
|
||||
|
||||
totalCargoText.text = player.totalCarga + "/" + player.GetMaxCargo();
|
||||
narcoCargoText.text = ""+player.cargoNarcos;
|
||||
naufCargoText.text = ""+player.cargoNauf;
|
||||
AngerBarUpdate();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
IEnumerator AngerDown()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (playing && bossAnger >=0)
|
||||
{
|
||||
bossAnger -= 0.02f;
|
||||
AngerBarUpdate();
|
||||
}
|
||||
yield return new WaitForSeconds(2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 48df30e358c64d244be0f0c65f98004e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,13 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class MapEdge : MonoBehaviour
|
||||
{
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D collision)
|
||||
{
|
||||
Destroy(collision.gameObject);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7c7d2229b1f64d04db851eecd06b8edd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,348 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class PlayerMov : MonoBehaviour
|
||||
{
|
||||
GameManager GM;
|
||||
Camera cam;
|
||||
|
||||
GameObject bar;
|
||||
|
||||
[Header("GUI")]
|
||||
public GameObject OverlayPanel;
|
||||
public GameObject progessBar;
|
||||
public GameObject UpgradesPanel;
|
||||
|
||||
public SpriteRenderer estadoSprite;
|
||||
|
||||
bool interactuando = false;
|
||||
|
||||
[Header("Sprites")]
|
||||
public Sprite descargaSprite;
|
||||
public Sprite maxCargaSprite;
|
||||
public Sprite voidSprite;
|
||||
|
||||
[Header("Mejoras Sprites")]
|
||||
public Sprite[] mejoraVelSprites = new Sprite[4];
|
||||
public Sprite[] mejoraCargoSprites = new Sprite[4];
|
||||
|
||||
|
||||
|
||||
[Header("GameObjects")]
|
||||
public GameObject destObject;
|
||||
public GameObject miraObject;
|
||||
public SpriteRenderer mejoraVelObject;
|
||||
public SpriteRenderer mejoraCargoObject;
|
||||
|
||||
|
||||
[Header("Times")]
|
||||
[SerializeField]
|
||||
float puertoTime = 5f;
|
||||
|
||||
float dTime;
|
||||
|
||||
[Header("Speeds")]
|
||||
[SerializeField]
|
||||
float defaultSpeed = 10f;
|
||||
[SerializeField]
|
||||
float rotSmooth = 5f;
|
||||
|
||||
float speed = 10f;
|
||||
|
||||
[Header("Ptos")]
|
||||
public Vector3 destPto;
|
||||
|
||||
public enum CargoType
|
||||
{
|
||||
narcos = 0, nauf = 1
|
||||
}
|
||||
|
||||
[Header("Cargas")]
|
||||
[SerializeField]
|
||||
public float maxCargo = 0;
|
||||
|
||||
public int cargoNarcos;
|
||||
public int cargoNauf;
|
||||
|
||||
public float totalCarga;
|
||||
|
||||
|
||||
|
||||
bool onPuertoNauf = false;
|
||||
bool onPuertoNarco = false;
|
||||
bool onPuertoMejora = false;
|
||||
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
GM = GameObject.FindGameObjectWithTag("GM").GetComponent<GameManager>();
|
||||
cam = GameObject.FindGameObjectWithTag("MainCamera").GetComponent<Camera>();
|
||||
|
||||
|
||||
bar = Instantiate(progessBar, OverlayPanel.transform, false);
|
||||
bar.SetActive(false);
|
||||
|
||||
//cargoText = Instantiate(cargoTextPref, OverlayPanel.transform, false);
|
||||
//cargoText.SetActive(true);
|
||||
|
||||
}
|
||||
|
||||
public void OnEnable()
|
||||
{
|
||||
speed = defaultSpeed;
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
|
||||
#region PlayerMov
|
||||
|
||||
if (GM.playing)
|
||||
{
|
||||
|
||||
Vector3 screenPto = cam.WorldToScreenPoint(transform.position);
|
||||
bar.transform.position = screenPto;
|
||||
|
||||
Vector3 mouseWorldPos = cam.ScreenToWorldPoint(Input.mousePosition);
|
||||
|
||||
miraObject.transform.position = mouseWorldPos;
|
||||
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
{
|
||||
destPto = new Vector3(mouseWorldPos.x, mouseWorldPos.y, 0);
|
||||
destObject.SetActive(true);
|
||||
destObject.transform.position = destPto;
|
||||
}
|
||||
|
||||
Vector3 mov = destPto - transform.position;
|
||||
|
||||
float angle = Vector2.SignedAngle(Vector2.right, mov);
|
||||
|
||||
Quaternion target = Quaternion.Euler(0, 0, angle);
|
||||
transform.rotation = Quaternion.Slerp(transform.rotation, target, Time.deltaTime * rotSmooth);
|
||||
|
||||
|
||||
if (mov.magnitude < 1)
|
||||
{
|
||||
destObject.SetActive(false);
|
||||
mov = new Vector3();
|
||||
}
|
||||
|
||||
|
||||
mov.Normalize();
|
||||
transform.position = transform.position + mov * speed * Time.timeScale * Time.deltaTime;
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
if (interactuando)
|
||||
{
|
||||
bar.GetComponent<Slider>().value = ((Time.time - dTime) / puertoTime);
|
||||
speed = 0;
|
||||
|
||||
if (bar.GetComponent<Slider>().value >= 1)
|
||||
{
|
||||
interactuando = false;
|
||||
bar.SetActive(false);
|
||||
speed = defaultSpeed;
|
||||
|
||||
}
|
||||
}else if (!interactuando)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D collision)
|
||||
{
|
||||
if(collision.gameObject.tag == "Puerto_Nauf")
|
||||
{
|
||||
onPuertoNauf = true;
|
||||
estadoSprite.sprite = descargaSprite;
|
||||
if (Input.GetKeyDown(KeyCode.F))
|
||||
{
|
||||
PuertoInteract(CargoType.nauf);
|
||||
}
|
||||
}
|
||||
else if(collision.gameObject.tag == "Puerto_Narcos")
|
||||
{
|
||||
onPuertoNarco = true;
|
||||
estadoSprite.sprite = descargaSprite;
|
||||
if (Input.GetKeyDown(KeyCode.F))
|
||||
{
|
||||
PuertoInteract(CargoType.narcos);
|
||||
}
|
||||
}
|
||||
else if(collision.gameObject.tag == "Puerto_Mejoras")
|
||||
{
|
||||
onPuertoMejora = true;
|
||||
estadoSprite.sprite = descargaSprite;
|
||||
if (Input.GetKeyDown(KeyCode.F))
|
||||
{
|
||||
Debug.Log("Mejoras");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTriggerStay2D(Collider2D collision)
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.F))
|
||||
{
|
||||
if (onPuertoNauf && collision.gameObject.tag == "Puerto_Nauf")
|
||||
{
|
||||
PuertoInteract(CargoType.nauf);
|
||||
}
|
||||
else if (onPuertoNarco && collision.gameObject.tag == "Puerto_Narcos")
|
||||
{
|
||||
PuertoInteract(CargoType.narcos);
|
||||
}
|
||||
else if (onPuertoMejora && collision.gameObject.tag == "Puerto_Mejoras")
|
||||
{
|
||||
GM.PlaySoundEffect(GameManager.soundEffects.select);
|
||||
Mejorando();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTriggerExit2D(Collider2D collision)
|
||||
{
|
||||
if (onPuertoNauf && collision.gameObject.tag == "Puerto_Nauf")
|
||||
{
|
||||
onPuertoNauf = false;
|
||||
}
|
||||
else if (onPuertoNarco && collision.gameObject.tag == "Puerto_Narcos")
|
||||
{
|
||||
onPuertoNarco = false;
|
||||
}
|
||||
else if (onPuertoMejora && collision.gameObject.tag == "Puerto_Mejoras")
|
||||
{
|
||||
onPuertoMejora = false;
|
||||
}
|
||||
estadoSprite.sprite = voidSprite;
|
||||
|
||||
}
|
||||
|
||||
private void PuertoInteract(CargoType type)
|
||||
{
|
||||
Debug.Log("Puerto " + type);
|
||||
|
||||
|
||||
dTime = Time.time;
|
||||
bar.GetComponent<Slider>().value = 0;
|
||||
bar.SetActive(true);
|
||||
|
||||
interactuando = true;
|
||||
|
||||
if (type == CargoType.narcos)
|
||||
{
|
||||
GM.DescargaPuerto(type, cargoNarcos);
|
||||
cargoNarcos = 0;
|
||||
}
|
||||
else if (type == CargoType.nauf)
|
||||
{
|
||||
GM.DescargaPuerto(type, cargoNauf);
|
||||
cargoNauf = 0;
|
||||
}
|
||||
totalCarga = cargoNarcos + cargoNauf;
|
||||
estadoSprite.sprite = voidSprite;
|
||||
}
|
||||
|
||||
private void Mejorando()
|
||||
{
|
||||
UpgradesPanel.SetActive(true);
|
||||
Time.timeScale = 0;
|
||||
}
|
||||
|
||||
|
||||
#region Speed
|
||||
public void SetPlayerSpeed(float p_speed)
|
||||
{
|
||||
speed = p_speed;
|
||||
}
|
||||
|
||||
public void ResetPlayerSpeed()
|
||||
{
|
||||
speed = defaultSpeed;
|
||||
}
|
||||
|
||||
public void SetPlayerDefaultSpeed(float default_Speed)
|
||||
{
|
||||
defaultSpeed = default_Speed;
|
||||
}
|
||||
|
||||
public float GetPlayerDefaultSpeed()
|
||||
{
|
||||
return defaultSpeed;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region Carga
|
||||
|
||||
public void AddCargo(CargoType type, int amount)
|
||||
{
|
||||
if(type == CargoType.narcos)
|
||||
{
|
||||
cargoNarcos += amount;
|
||||
}else if(type == CargoType.nauf)
|
||||
{
|
||||
cargoNauf += amount;
|
||||
}
|
||||
totalCarga = cargoNarcos + cargoNauf;
|
||||
}
|
||||
|
||||
public void SetLlenoSprite()
|
||||
{
|
||||
estadoSprite.sprite = maxCargaSprite;
|
||||
}
|
||||
|
||||
public void SetMaxCargo(int value)
|
||||
{
|
||||
maxCargo = value;
|
||||
}
|
||||
|
||||
public int GetMaxCargo()
|
||||
{
|
||||
return Mathf.RoundToInt(maxCargo);
|
||||
}
|
||||
|
||||
|
||||
public bool IsFullCarga()
|
||||
{
|
||||
if(totalCarga >= maxCargo)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Upgrades
|
||||
|
||||
|
||||
public enum MejoraLevel
|
||||
{
|
||||
MK1 = 0, MK2 = 1, MK3 = 2, MK4 = 3
|
||||
}
|
||||
|
||||
public void SetMejoraSpeedSprite(MejoraLevel level)
|
||||
{
|
||||
mejoraVelObject.sprite = mejoraVelSprites[(int)level];
|
||||
}
|
||||
|
||||
public void SetMejoraCargoSprite(MejoraLevel level)
|
||||
{
|
||||
mejoraCargoObject.sprite = mejoraCargoSprites[(int)level];
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 46572532a70f6854e81b468903d88748
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4accae232f5a0584d835e4ae4824d60f
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,60 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
|
||||
public class EndSceneManager : MonoBehaviour
|
||||
{
|
||||
|
||||
/*public int rescatados;
|
||||
public int detenidos;
|
||||
public int huidos;
|
||||
public int muertos;
|
||||
float musicVol;
|
||||
float effectsVol;
|
||||
public float gameTime;*/
|
||||
|
||||
public AudioSource music;
|
||||
|
||||
|
||||
[SerializeField]
|
||||
TMPro.TMP_Text rescatadosText = null;
|
||||
[SerializeField]
|
||||
TMPro.TMP_Text muertosText = null;
|
||||
[SerializeField]
|
||||
TMPro.TMP_Text capturadosText = null;
|
||||
[SerializeField]
|
||||
TMPro.TMP_Text huidosText = null;
|
||||
[SerializeField]
|
||||
TMPro.TMP_Text timeText = null;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
|
||||
music.volume = DataSave.musicVol;
|
||||
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
UpdateTexts();
|
||||
}
|
||||
|
||||
|
||||
public void BackToMenuButton()
|
||||
{
|
||||
SceneManager.LoadSceneAsync(0, LoadSceneMode.Single);
|
||||
}
|
||||
|
||||
private void UpdateTexts()
|
||||
{
|
||||
rescatadosText.text += DataSave.rescatados;
|
||||
muertosText.text += DataSave.muertos;
|
||||
capturadosText.text += DataSave.detenidos;
|
||||
huidosText.text += DataSave.huidos;
|
||||
|
||||
timeText.text += Mathf.Round(DataSave.gameTime) + "s";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 007f21bbb64e03746aee5204a9c97835
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,87 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class GameUIManager : MonoBehaviour
|
||||
{
|
||||
GameManager GM;
|
||||
|
||||
|
||||
[Header("GUI")]
|
||||
public GameObject startMenu;
|
||||
public GameObject inGameMenu;
|
||||
public GameObject OverlayPanel;
|
||||
|
||||
[Header("HelpPanels")]
|
||||
public GameObject Panel1;
|
||||
public GameObject Panel2;
|
||||
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
GM = GameObject.FindGameObjectWithTag("GM").GetComponent<GameManager>();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
StartingUI();
|
||||
}
|
||||
|
||||
|
||||
public void NextWindowButton()
|
||||
{
|
||||
Panel1.SetActive(false);
|
||||
Panel2.SetActive(true);
|
||||
}
|
||||
|
||||
public void PreviousWindowButton()
|
||||
{
|
||||
Panel1.SetActive(true);
|
||||
Panel2.SetActive(false);
|
||||
}
|
||||
|
||||
public void StartButton()
|
||||
{
|
||||
GM.StartGame();
|
||||
}
|
||||
|
||||
public void BackMenuButton()
|
||||
{
|
||||
SceneManager.LoadSceneAsync(0, LoadSceneMode.Single);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#region UI States
|
||||
|
||||
public void StartingUI()
|
||||
{
|
||||
startMenu.SetActive(true);
|
||||
OverlayPanel.SetActive(false);
|
||||
inGameMenu.SetActive(false);
|
||||
|
||||
Panel1.SetActive(true);
|
||||
Panel2.SetActive(false);
|
||||
}
|
||||
|
||||
public void InGameUI()
|
||||
{
|
||||
startMenu.SetActive(false);
|
||||
OverlayPanel.SetActive(true);
|
||||
inGameMenu.SetActive(true);
|
||||
}
|
||||
|
||||
public void EndGameUI()
|
||||
{
|
||||
startMenu.SetActive(false);
|
||||
inGameMenu.SetActive(false);
|
||||
OverlayPanel.SetActive(false);
|
||||
SceneManager.LoadSceneAsync(2, LoadSceneMode.Single);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d4d3892194eac024d94d8fd2f5fd54a4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,64 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.Audio;
|
||||
|
||||
public class MainMenuManager : MonoBehaviour
|
||||
{
|
||||
|
||||
public GameObject MenuPanel;
|
||||
public GameObject SettingsPanel;
|
||||
|
||||
|
||||
|
||||
public AudioSource musicSource;
|
||||
public AudioSource effectsSource;
|
||||
|
||||
public Slider volMusicSlider;
|
||||
public Slider volEffectSlider;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
MenuPanel.SetActive(true);
|
||||
SettingsPanel.SetActive(false);
|
||||
|
||||
musicSource.Play();
|
||||
|
||||
effectsSource.volume = 0.5f;
|
||||
musicSource.volume = 0.5f;
|
||||
}
|
||||
|
||||
public void PlayButton()
|
||||
{
|
||||
StartCoroutine("PlayButtonRoutine");
|
||||
}
|
||||
|
||||
public void SetMusicVol()
|
||||
{
|
||||
DataSave.musicVol = volMusicSlider.value;
|
||||
musicSource.volume = volMusicSlider.value;
|
||||
}
|
||||
|
||||
public void SetEffectsVol()
|
||||
{
|
||||
DataSave.effectsVol = volEffectSlider.value;
|
||||
effectsSource.volume = volEffectSlider.value;
|
||||
}
|
||||
|
||||
|
||||
IEnumerator PlayButtonRoutine()
|
||||
{
|
||||
for(int i = 255; i > 0; i -= 3)
|
||||
{
|
||||
Debug.Log("For Start");
|
||||
MenuPanel.GetComponent<Image>().color = new Color(0, 0, 0, i/255f);
|
||||
yield return new WaitForEndOfFrame();
|
||||
}
|
||||
|
||||
Debug.Log("Scene");
|
||||
SceneManager.LoadSceneAsync(1, LoadSceneMode.Single);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 93579bb7a8d5cc1499502d99c56452d1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,175 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class UpgradeManager : MonoBehaviour
|
||||
{
|
||||
|
||||
GameManager GM;
|
||||
PlayerMov PM;
|
||||
|
||||
public GameObject upgradesPanel;
|
||||
|
||||
int mejoraVel = 0;
|
||||
int mejoraCargo = 0;
|
||||
|
||||
[Header("UpdateVars")]
|
||||
public float speedIncreasePerLevel;
|
||||
public int cargoIncreasePerLevel;
|
||||
|
||||
public int[] UpgradeCost = new int[3];
|
||||
|
||||
|
||||
[Header("UI Elements")]
|
||||
public Image[] mejoraVelLevel = new Image[3];
|
||||
public Image[] mejoraCargoLevel = new Image[3];
|
||||
|
||||
public Text mejoraVelCostText;
|
||||
public Text mejoraCargoCostText;
|
||||
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
GM = GameObject.FindGameObjectWithTag("GM").GetComponent<GameManager>();
|
||||
PM = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerMov>();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
mejoraVelCostText.text = UpgradeCost[0] + "€";
|
||||
mejoraCargoCostText.text = UpgradeCost[0] + "€";
|
||||
upgradesPanel.SetActive(false);
|
||||
}
|
||||
|
||||
public void MejoraVelButton()
|
||||
{
|
||||
if (mejoraVel < 3)
|
||||
{
|
||||
switch (mejoraVel)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
if (GM.money >= UpgradeCost[mejoraVel])
|
||||
{
|
||||
GM.money -= UpgradeCost[mejoraVel];
|
||||
PM.SetMejoraSpeedSprite(PlayerMov.MejoraLevel.MK2);
|
||||
PM.SetPlayerDefaultSpeed(PM.GetPlayerDefaultSpeed() + speedIncreasePerLevel);
|
||||
for (int i = 0; i <= mejoraVel; i++)
|
||||
{
|
||||
mejoraVelLevel[i].gameObject.SetActive(true);
|
||||
}
|
||||
mejoraVel += 1;
|
||||
mejoraVelCostText.text = UpgradeCost[mejoraVel] + "€";
|
||||
GM.PlaySoundEffect(GameManager.soundEffects.powerup);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
if (GM.money >= UpgradeCost[mejoraVel])
|
||||
{
|
||||
GM.money -= UpgradeCost[mejoraVel];
|
||||
PM.SetMejoraSpeedSprite(PlayerMov.MejoraLevel.MK3);
|
||||
PM.SetPlayerDefaultSpeed(PM.GetPlayerDefaultSpeed() + speedIncreasePerLevel);
|
||||
for (int i = 0; i <= mejoraVel; i++)
|
||||
{
|
||||
mejoraVelLevel[i].gameObject.SetActive(true);
|
||||
}
|
||||
mejoraVel += 1;
|
||||
mejoraVelCostText.text = UpgradeCost[mejoraVel] + "€";
|
||||
GM.PlaySoundEffect(GameManager.soundEffects.powerup);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
if (GM.money >= UpgradeCost[mejoraVel])
|
||||
{
|
||||
GM.money -= UpgradeCost[mejoraVel];
|
||||
PM.SetMejoraSpeedSprite(PlayerMov.MejoraLevel.MK4);
|
||||
PM.SetPlayerDefaultSpeed(PM.GetPlayerDefaultSpeed() + speedIncreasePerLevel);
|
||||
for (int i = 0; i <= mejoraVel; i++)
|
||||
{
|
||||
mejoraVelLevel[i].gameObject.SetActive(true);
|
||||
}
|
||||
mejoraVel += 1;
|
||||
mejoraVelCostText.text = "Max Level";
|
||||
GM.PlaySoundEffect(GameManager.soundEffects.powerup);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
PM.ResetPlayerSpeed();
|
||||
}
|
||||
}
|
||||
|
||||
public void MejoraCargoButton()
|
||||
{
|
||||
if (mejoraCargo < 3)
|
||||
{
|
||||
switch (mejoraCargo)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
if (GM.money >= UpgradeCost[mejoraCargo])
|
||||
{
|
||||
GM.money -= UpgradeCost[mejoraCargo];
|
||||
PM.SetMejoraCargoSprite(PlayerMov.MejoraLevel.MK2);
|
||||
PM.SetMaxCargo(PM.GetMaxCargo() + cargoIncreasePerLevel);
|
||||
for (int i = 0; i <= mejoraCargo; i++)
|
||||
{
|
||||
mejoraCargoLevel[i].gameObject.SetActive(true);
|
||||
}
|
||||
mejoraCargo += 1;
|
||||
mejoraCargoCostText.text = UpgradeCost[mejoraCargo] + "€";
|
||||
GM.PlaySoundEffect(GameManager.soundEffects.powerup);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
if (GM.money >= UpgradeCost[mejoraCargo])
|
||||
{
|
||||
GM.money -= UpgradeCost[mejoraCargo];
|
||||
PM.SetMejoraCargoSprite(PlayerMov.MejoraLevel.MK3);
|
||||
PM.SetMaxCargo(PM.GetMaxCargo() + cargoIncreasePerLevel);
|
||||
for (int i = 0; i <= mejoraCargo; i++)
|
||||
{
|
||||
mejoraCargoLevel[i].gameObject.SetActive(true);
|
||||
}
|
||||
mejoraCargo += 1;
|
||||
mejoraCargoCostText.text = UpgradeCost[mejoraCargo] + "€";
|
||||
GM.PlaySoundEffect(GameManager.soundEffects.powerup);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
if (GM.money >= UpgradeCost[mejoraCargo])
|
||||
{
|
||||
GM.money -= UpgradeCost[mejoraCargo];
|
||||
PM.SetMejoraCargoSprite(PlayerMov.MejoraLevel.MK4);
|
||||
PM.SetMaxCargo(PM.GetMaxCargo() + cargoIncreasePerLevel);
|
||||
for (int i = 0; i <= mejoraCargo; i++)
|
||||
{
|
||||
mejoraCargoLevel[i].gameObject.SetActive(true);
|
||||
}
|
||||
mejoraCargo += 1;
|
||||
mejoraCargoCostText.text = "Max Level";
|
||||
GM.PlaySoundEffect(GameManager.soundEffects.powerup);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void CloseUpgradeButton()
|
||||
{
|
||||
upgradesPanel.SetActive(false);
|
||||
Time.timeScale = 1;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7ce566e4e98b2a149894d9dfb2ead937
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user