예제 #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);
    }
예제 #2
0
    public GameObject spawnEnemy(string name, Avatar.AvatarType avatarType, Vector3 position)
    {
        GameObject newGameObj = new GameObject();

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

        Enemy avatarComponent = newGameObj.AddComponent <Enemy>();

        avatarComponent.initialEnemy(avatarType, newGameObj.name);
        Sprite[] spriteMulti = Resources.LoadAll <Sprite>("Sprites/Avatars");
        Sprite   sprite      = spriteMulti.Single(s => s.name == newGameObj.name);

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

        return(newGameObj);
    }