Well, If question a bit confusing let me explain clearly. I was trying to make a really basic upgrade menu after every level for each defender. So players have their own fate in their hands since after every level they decide which defender they want to upgrade as you see in the below.
In order to do what I actually want I draw new defenders for example archer and took archer’s prefab changed sprites,health,name etc. and saved as a new character.
After that, I wrote a script similar to buttonScript which I give people a desicion as I screenshot on above.
What I did in script, when player select one symbol changed other’s color and disabled their colliders.
Now player selected to upgrade wheat>>sprite changed to new one
Since selected defenders have different prefab, in code I changed also the prefab that buttons hold with buttonscript.
public GameObject defenderPrefab;
public Sprite upgradedSprite;
public bool hocabitir = false;
private int krema = 0;
private upgradeButton[] buttonArray;
private ButtonScript[] buttons;
private gameTimer gametimer;
void Start () {
buttonArray = GameObject.FindObjectsOfType<upgradeButton>();
buttons = GameObject.FindObjectsOfType<ButtonScript>();
gametimer = GameObject.FindObjectOfType<gameTimer>();
}
{
if (this.name == buton.name && krema<=1)
{
buton.GetComponent<ButtonScript>().defenderPrefab = defenderPrefab;
buton.GetComponent<BoxCollider2D>().isTrigger = false;
krema = krema + 1;
hocabitir = true;
gametimer.idEndOfLevel2 = true;
}
}
I put the code here to show just how I changed the Buttons GameObjects defenderPrefab; Lets look at in unity the results of this change:
So at the end I changed something in the scene just before the nextlevel however It doesnt apply to prefab since I dont know how to apply changes to prefab in runtime. With this new gameObject I want to take this information and use it in the next level. How should I achieve my goal ? If you read until here and have no solution at least thanks for the patience =) Have a good day!