Hi, I have an Array for 2 players. I am adding a list of string names to the array as a player clicks on items. When the player closes the window I am trying to Instantiate items to the game but I am getting an errors.
And this error
I’m pretty sure I understand the errors, the Instantiate() method is looking for the prefab for it’s first argument and I am passing it a string that has the name of the prefab I want it to Instantiate.
Here is the code so far, it is still a work in progress, but I am looking for a way to store the names and then instantiate the Prefabs based on the name of string names in the array?
public void purchaseItemButton(string name){ // When button is pushed, pass the name of the prefab you want
float cameraPos = Camera.main.transform.position.x;
bool isRight = (cameraPos > 0) ? true : false;
if(isRight){
if(playerRArray.Length < 5){
playerRArray[playerRArray.Length] = name; // add the purchased name of item to the player array
}
else{
print("To many items");
}
}
else{
}
}
public void buyingStoreHideShow(bool state){
float cameraPos = Camera.main.transform.position.x; // Check which side the camera is on to determin the player.
bool isRight = (cameraPos > 0) ? true : false;
if(isRight){
for(int i = 0; i < playerRArray.Length; i++){
Button but = Instantiate(playerRArray[i],Vector3.zero,Quaternion.identity);
}
}
GameObject sm = GameObject.Find("Canvas/Store");
int count = sm.transform.childCount;
for(int i = 0; i < count; i++){
sm.transform.GetChild(i).gameObject.SetActive(state);
}
bool tempState = (state == true) ? false : true;
WindSpeedGraphics(tempState);
PlayerRHide_Show(tempState); // hide user standard graphics when looking at the Store
}