|
Post by callmeace on Oct 6, 2017 7:54:15 GMT
Hello, I been working with the third person shooter template for about a month now and had a question about how to go about making something like a character selection. I have 5 different models and when a player starts a new game they can select there character which then loads into the main world anyone have any idea how I can do this?
|
|
|
Post by witcher on Oct 6, 2017 8:30:11 GMT
This is very easy you just instantiate the prefab you want when you click on Character UI
|
|
|
Post by callmeace on Oct 6, 2017 9:52:35 GMT
That's what I thought I was doing I wrote a script to toggle through available characters I created 5 different shooter controllers with invector using my different models. I set there position then removed them from the scene put the into a folder well here is the script maybe i did something wrong because every time i press play cant move character and get errors. Here is how i got it written out.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class CharacterSelect : MonoBehaviour {
public List<GameObject> characterList;
public int index=0;
//Get list of characters in Resource/prefab folder
void Start () {
index = PlayerPrefs.GetInt ("CharacterSelected");
GameObject[] characters = Resources.LoadAll<GameObject> ("CharacterPrefab");
foreach (GameObject c in characters) {
GameObject _char = Instantiate (c) as GameObject;
_char.transform.SetParent (GameObject.Find ("CharacterList").transform);
characterList.Add (_char);
_char.SetActive (false);
characterList [index].SetActive (true);
}
}
//Toggle my characters
public void Next() {
characterList [index].SetActive (false);
if (index == characterList.Count - 1) {
index = 0;
} else {
index++;
}
characterList [index].SetActive (true);
}
//toggle my previous character public void Previous(){
characterList [index].SetActive (false);
if (index == 0) {
index = characterList.Count-1;
} else {
index--;
}
characterList [index].SetActive (true);
}
// chooses my character and load next scene
public void Play()
{
PlayerPrefs.SetInt ("characterSelected", index);
SceneManager.LoadScene ("Starting Area");
}
}
|
|
|
Post by witcher on Oct 6, 2017 10:58:18 GMT
you should post errors
|
|