Esempio n. 1
0
    public virtual GameObject SpawnHero(Player p, Vector2 newSpawnPoint)
    {
        //create an instance of the hero so the player can try it out in the selection screen
        Hero       hero   = (Instantiate(p.Hero.Prefab) as GameObject).GetComponent <Hero>();
        Weapon     ranged = (Instantiate(p.FirstWeapon.Prefab) as GameObject).GetComponent <Weapon>();
        Weapon     melee  = (Instantiate(p.SecondWeapon.Prefab) as GameObject).GetComponent <Weapon>();
        Damageable dmg    = hero.GetComponent <Damageable>();

        dmg.OnDestroy += OnPlayerKilled;

        //put the weapons into hero's hands
        ranged.transform.parent        = hero.transform.FindChild("Hand1");
        melee.transform.parent         = hero.transform.FindChild("Hand2");
        ranged.transform.localPosition = Vector2.zero;
        melee.transform.localPosition  = Vector2.zero;

        //give the soul to the flesh
        hero.SetPlayer(p);

        //weapons need to know their owner gameobject (the hero, not the player!)
        ranged.SetOwner(hero.gameObject);
        melee.SetOwner(hero.gameObject);

        //place hero  in scene
        hero.transform.position = newSpawnPoint;

        //spawn a particle effect
        SpawnParticle(newSpawnPoint, p.InTeam.TeamColor);

        if (_gameEnded)
        {
            Destroy(hero.GetComponent <HeroControllerV2>());
            Destroy(hero.GetComponent <HeroController>());
        }
        if (RespawnSound != null)
        {
            RespawnSound.PlayEffect();
        }

        _camera.AddPlayer(hero.transform);
        return(hero.gameObject);
    }