NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class GameController : MonoBehaviour
{
public static GameController Instance;

public int battleSceneNum;

private int levelsCompleted = 0;

public List<UnitData> playerUnitData = new List<UnitData>();

public List<UnitBattleController> enemyBattleUnits = new List<UnitBattleController>();
public List<UnitBattleController> playerBattleUnits = new List<UnitBattleController>();

public GameObject[] playerUnits;
public GameObject[] enemyUnits;
public UnitData[] enemyUnitData;

public Vector3[] playerBattleLocs;
public Vector3[] enemyBattleLocs;

public GameObject globalMapObject;

private bool bossBattle = false;
private int bossBattleNum = -1;

public int currScene = 0;

public GameObject healthBar;

private Vector3 battleStartLocation;
private GameObject playerObject;
private bool battleStarting = false;

//Number of levels, max number of triggers or any level
public bool[,] levelTriggers = new bool[1, 1];

public int coins = 37;

private void Awake()
{
if (Instance != null && Instance != this)
{
DestroyImmediate(gameObject);
return;
}

DontDestroyOnLoad(this);
Instance = this;
}

// Start is called before the first frame update
void Start()
{
for(int LNum = 0; LNum < levelTriggers.GetLength(0); LNum++)
{
for(int tNum = 0; tNum < levelTriggers.GetLength(1); tNum++)
{
levelTriggers[LNum, tNum] = true;
}
}

enemyUnitData = new UnitData[enemyUnits.Length];

playerUnitData.Add(new UnitData());
playerUnitData.Add(new UnitData());
playerUnitData.Add(new UnitData());
playerUnitData[0].SetClass(0);
playerUnitData[1].SetClass(1);
playerUnitData[2].SetClass(2);
SetEnemyUnitDatas();


battleSceneNum = SceneManager.sceneCountInBuildSettings - 1;
SceneManager.sceneLoaded += OnSceneLoaded;
}

public void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
if(scene.buildIndex == battleSceneNum)
{
DeployUnits();
}else if(scene.buildIndex != 0)
{
globalMapObject.SetActive(false);
CanvasController.Instance.OpenLevelUI();
currScene = scene.buildIndex;
playerObject = GameObject.Find("Player");
if (battleStarting)
{
battleStarting = false;
playerObject.transform.position = battleStartLocation;
}
}
}

// Update is called once per frame
void Update()
{

}

public int GetLevelsCompleted()
{
return levelsCompleted;
}

public void SetLevelsCompleted(int levels)
{
levelsCompleted = levels;
}

public void StartBattle()
{
battleStarting = true;
battleStartLocation = playerObject.transform.position;
SceneManager.LoadScene(battleSceneNum);
CanvasController.Instance.StartBattle();
}

public void DeployUnits()
{
if (bossBattle)
{
bossBattle = false;

switch (bossBattleNum)
{
case 1:
DeployEnemyUnit(0, 0);
DeployEnemyUnit(1, 2);
break;
default:
break;
}
}
else
{
DeployRandomEnemyUnits(0, 2);
}
DeployPlayerUnits();

}

public void SetBossBattle(int battleNum)
{
bossBattle = true;
bossBattleNum = battleNum;
}

private void DeployPlayerUnits()
{
for(int i = 0; i < playerBattleLocs.Length; i++)
{
if (!playerUnitData[i].GetIsDead())
{
GameObject g = Instantiate(playerUnits[playerUnitData[i].GetClass()], playerBattleLocs[i], Quaternion.identity);
UnitBattleController ubc = g.GetComponent<UnitBattleController>();

ubc.isPlayerUnit = true;
playerBattleUnits.Add(ubc);
ubc.SetUnitData(playerUnitData[i]);

GameObject hb = Instantiate(healthBar, new Vector3(g.transform.position.x,
g.transform.position.y + 2, g.transform.position.z), Quaternion.Euler(0, -90, 0));
hb.transform.SetParent(g.transform);

ubc.SetHealthbar(hb);
ubc.AdjustHealthBar();

g.transform.SetPositionAndRotation(g.gameObject.transform.position, Quaternion.Euler(0, 90, 0));
}
}
}

private void DeployEnemyUnit(int enemyNum, int enemyLocation)
{
GameObject g = Instantiate(enemyUnits[enemyNum], enemyBattleLocs[enemyLocation], Quaternion.identity);

enemyBattleUnits.Add(g.GetComponent<UnitBattleController>());
UnitData cloneEnemyData = CloneClass.Clone<UnitData>(enemyUnitData[enemyNum]);

BattleController.Instance.enemyUnitTempData.Add(cloneEnemyData);
g.GetComponent<UnitBattleController>().SetUnitData(cloneEnemyData);

GameObject hb = Instantiate(healthBar, new Vector3(g.transform.position.x,
g.transform.position.y + 3, g.transform.position.z), Quaternion.Euler(0, 90, 0));
hb.transform.SetParent(g.transform);
g.GetComponent<UnitBattleController>().SetHealthbar(hb);

g.transform.SetPositionAndRotation(g.gameObject.transform.position, Quaternion.Euler(0, -90, 0));
}

public void DeployRandomEnemyUnits(int minIndex, int maxIndex)
{
for(int i = 0; i < 3; i++)
{
int enemyNum = Random.Range(minIndex, maxIndex + 1);
DeployEnemyUnit(enemyNum, i);
}
}

public void SetEnemyUnitDatas()
{
enemyUnitData[0] = new UnitData();
enemyUnitData[0].SetClass(0);
enemyUnitData[0].SetStatistics();

enemyUnitData[1] = new UnitData();
enemyUnitData[1].SetClass(0);
enemyUnitData[1].SetStatistics();

enemyUnitData[2] = new UnitData();
enemyUnitData[2].SetClass(0);
enemyUnitData[2].SetStatistics();
}

public UnitData GetPlayerUnitData(int unitNum)
{
return playerUnitData[unitNum];
}

public void FightReturn(bool playerWon)
{
if (playerWon)
{
SceneManager.LoadScene(currScene);
CanvasController.Instance.EndBattle();
}
else
{
//LoseScreen
SceneManager.LoadScene(0);
}
}
}

     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.