Esempio n. 1
0
    // 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);
        }
    }
Esempio n. 2
0
    // Spawn's the lightning unit and returns a reference to it, takes in an optional spawnHex
    public Unit SpawnLightningUnit(Hex spawnHex = null)
    {
        // use spawn points by default
        if (spawnHex == null)
        {
            GameObject lightningGO = GameObject.FindGameObjectWithTag("LightningUnitSpawn");

            if (lightningGO)
            {
                Hex spawnHexLightning = lightningGO.transform.parent.GetComponent <Hex>();

                Vector3 spawnPosLightning = spawnHexLightning.transform.position;
                spawnPosLightning.y = spawnYLevel;

                lightningUnit = Instantiate(Resources.Load <LightningUnit>("PlayerCharacters/LightningUnit"), spawnPosLightning, Quaternion.identity);
                lightningUnit.Spawn(spawnHexLightning);

                lightningUnit.GetComponent <OverworldFollower>().Init();

                lightningUnit.OnDeath += PlayerUnitDied;

                lightningDead = false;

                return(lightningUnit);
            }
            else
            {
                Debug.LogError("No lightning spawn point found!");

                return(null);
            }
        }
        else
        {
            // spawn at checkpoint pos

            Vector3 spawnPosLightning = spawnHex.transform.position;
            spawnPosLightning.y = spawnYLevel;

            lightningUnit = Instantiate(Resources.Load <LightningUnit>("PlayerCharacters/LightningUnit"), spawnPosLightning, Quaternion.identity);
            lightningUnit.Spawn(spawnHex);

            lightningUnit.GetComponent <OverworldFollower>().Init();

            lightningUnit.OnDeath += PlayerUnitDied;

            lightningDead = false;

            return(lightningUnit);
        }
    }