public void AddNewPetForStage() { int id; do { id = Random.Range(0, PetViewController.PET_ID_RANGER); } while (PlayerData.instance.CheckIDExisted(id)); GameObject _new_pet_view = Instantiate(PetViewPrefab, Vector3.zero, Quaternion.identity, transform); PetView _pet_view = _new_pet_view.GetComponent <PetView>(); _pet_view.NewPet(id, PetKind, GetNewPetName()); _new_pet_view.GetComponent <SpriteRenderer>().enabled = false; PlayerData.instance.SavePlayerData(); }
public void NewPetView(string _kind, string _name) { /* Random a id */ int id; do { id = Random.Range(0, PET_ID_RANGER); } while(PlayerData.instance.CheckIDExisted(id)); //while (!CheckID(id)); /* A insatnced position in background*/ Vector3 new_view_pos = Vector3.zero + new Vector3(Random.Range(-ContainerWidth * PET_VIEWS_POS_RANGE, ContainerWidth * PET_VIEWS_POS_RANGE), Random.Range(0, ContainerHeight * PET_VIEWS_POS_RANGE), 0); /* Instantiate PetView prefab and load it data by it's id */ GameObject _new_pet_view = Instantiate(PetViewPrefab, new_view_pos, Quaternion.identity, transform); PetView _pet_view = _new_pet_view.GetComponent <PetView>(); _pet_view.NewPet(id, _kind, _name); pets_view_data.Add(_pet_view); PlayerData.instance.SavePlayerData(); }