Ejemplo n.º 1
0
        // Start is called before the first frame update
        void Start()
        {
            if (PlayerPrefs.HasKey(StringConsts.CURRENT_CHARACTER))
            {
                var characterTag = PlayerPrefs.GetString(StringConsts.CURRENT_CHARACTER);
                foreach (var character in charactersList)
                {
                    if (character.tag == characterTag)
                    {
                        GameObject newCharacter = Instantiate(character, startPosition, Quaternion.identity);
                        PlayerInstance.setInstance(newCharacter.GetComponent <PlayerBehaviour>());
                        EventsController.AddToFreezableItems(newCharacter.GetComponent <PlayerBehaviour>());
                        break;
                    }
                }
            }
            else
            {
                PlayerPrefs.SetString(StringConsts.START_CHARACTER, StringConsts.EQUIPED);
                PlayerPrefs.SetString(StringConsts.CURRENT_CHARACTER, StringConsts.START_CHARACTER);

                foreach (var character in charactersList)
                {
                    if (character.tag == StringConsts.START_CHARACTER)
                    {
                        GameObject newCharacter = Instantiate(character, startPosition, Quaternion.identity);
                        PlayerInstance.setInstance(newCharacter.GetComponent <PlayerBehaviour>());
                        EventsController.AddToFreezableItems(newCharacter.GetComponent <PlayerBehaviour>());
                    }
                }
            }
            PlayerPrefs.Save();
        }
Ejemplo n.º 2
0
        public static void ChangeCharacter(string newCharacterTag)
        {
            EventsController.RemoveFromFreezable(PlayerInstance.getInstance());
            Destroy(PlayerInstance.getInstance().gameObject);

            foreach (var character in charactersList)
            {
                if (character.tag == newCharacterTag)
                {
                    GameObject newCharacter = Instantiate(character, startPosition, Quaternion.identity);
                    PlayerInstance.setInstance(newCharacter.GetComponent <PlayerBehaviour>());
                    EventsController.AddToFreezableItems(newCharacter.GetComponent <PlayerBehaviour>());
                    break;
                }
            }
        }
Ejemplo n.º 3
0
 // Start is called before the first frame update
 void Start()
 {
     rb            = GetComponent <Rigidbody2D>();
     startPosition = transform.position;
     EventsController.AddToFreezableItems(this);
 }