Skip to content

develop Character Select

Jeon-YJ1004 edited this page Mar 9, 2023 · 1 revision

Character Select

  1. CharacterSelection.scene Hierachy에 Create Empty, 아래 처럼 설정

image

  1. Character 버튼에 On Click() 지정

image

  1. PlayerMovement.cs에 Awake 할때 애니메이터를 바꾸는 코드 추가
[PlayerMovement.cs]
private void Awake()
    {
       //애니메이터 파일 이름을 설정 ex> Animator/Heroknight
        string resourceName = "Animator/" + DataManager.instance.currentCharcter;
       //실행중에 에니메이터 바꾸기. Resources.Load()는 path의 파일을 load한다. Asset>Resource가 root 경로
        animator.runtimeAnimatorController = Resources.Load<RuntimeAnimatorController>(resourceName);
    }

[DataManager.cs]
public enum CharacterName
{
    Alchemist, Barbarian, Blademaster, Druid,FireMage, KnightHero, Necromancer
}
public class DataManager : MonoBehaviour
{
    public static DataManager instance;
    public CharacterName currentCharcter;
    private void Awake()
    {
        instance = this;
        DontDestroyOnLoad(gameObject);
    }   
}

[SelectCharacter.cs]
public class SelectCharacter : MonoBehaviour
{
    public CharacterName charname;
    public void OnClickCharacter()
    {
        DataManager.instance.currentCharcter=charname;
        Debug.Log(DataManager.instance.currentCharcter);
    }
}
Clone this wiki locally