// Spawn's the earth unit and returns a reference to it, takes in an optional spawnHex public Unit SpawnEarthUnit(Hex spawnHex = null) { // use spawn points by default if (spawnHex == null) { GameObject earthGO = GameObject.FindGameObjectWithTag("EarthUnitSpawn"); if (earthGO) { Hex spawnHexEarth = earthGO.transform.parent.GetComponent <Hex>(); Vector3 spawnPosEarth = spawnHexEarth.transform.position; spawnPosEarth.y = spawnYLevel; earthUnit = Instantiate(Resources.Load <EarthUnit>("PlayerCharacters/EarthUnit"), spawnPosEarth, Quaternion.identity); earthUnit.Spawn(spawnHexEarth); cameraRig.Init(); if (lightningUnit) { lightningUnit.GetComponent <OverworldFollower>().Init(); } earthUnit.OnDeath += PlayerUnitDied; earthDead = false; return(earthUnit); } else { Debug.LogError("No Earth spawn point found!"); return(null); } } else { // spawn at checkpoint pos Vector3 spawnPosEarth = spawnHex.transform.position; spawnPosEarth.y = spawnYLevel; earthUnit = Instantiate(Resources.Load <EarthUnit>("PlayerCharacters/EarthUnit"), spawnPosEarth, Quaternion.identity); earthUnit.Spawn(spawnHex); earthUnit.OnDeath += PlayerUnitDied; earthDead = false; return(earthUnit); } }