Exemplo n.º 1
0
    public GameObject spawnNewHero(string name, Avatar.AvatarStatus avatarStatus, Avatar.AvatarType avatarType, Vector3 position)
    {
        GameObject avatarObject = new GameObject();

        avatarObject.name = name;
        avatarObject.tag  = "Hero";
        avatarObject.transform.position   = position;
        avatarObject.transform.localScale = new Vector3(2, 2, 1);

        AddStar(avatarObject, avatarStatus);

        Hero avatarComponent = avatarObject.AddComponent <Hero>();

        avatarComponent.initialHero(avatarStatus, avatarType, avatarObject.name, Hero.Direction.Right);
        Sprite[] spriteMulti = Resources.LoadAll <Sprite>("Sprites/Avatars");
        Sprite   sprite      = spriteMulti.Single(s => s.name == avatarObject.name);

        avatarObject.AddComponent <SpriteRenderer>();
        avatarObject.GetComponent <SpriteRenderer>().sprite = sprite;
        avatarObject.AddComponent <BoxCollider2D>();
        avatarObject.AddComponent <Rigidbody2D>();
        avatarObject.GetComponent <Rigidbody2D>().gravityScale = 0;
        avatarObject.GetComponent <Rigidbody2D>().constraints  = RigidbodyConstraints2D.FreezeRotation;

        return(avatarObject);
    }
Exemplo n.º 2
0
    void AddStar(GameObject avatarObject, Avatar.AvatarStatus avatarStatus)
    {
        GameObject starObject = new GameObject();

        starObject.name = "Star";
        Sprite starSprite = Resources.Load <Sprite>("Sprites/Yellow_Star");

        starObject.AddComponent <SpriteRenderer>();
        starObject.GetComponent <SpriteRenderer>().sprite = starSprite;
        starObject.transform.SetParent(avatarObject.transform);
        starObject.transform.localScale    = new Vector3(0.05f, 0.05f, 1);
        starObject.transform.localPosition = new Vector3(0, 0.5f, 0);
        if (avatarStatus != Avatar.AvatarStatus.Hero_leader)
        {
            starObject.SetActive(false);
        }
    }