- Home /
Set the same value to a new Game object as the old one?
I am trying to make a game with turrets which should be upgraded and when they do I want the new instantiated prefab to assign the same values as the old turret. Since they have the exact same script it should be possible, right? I DO NOT want to change the value in the inspector because it just messes up all the values. I'm making it in C#. Thanks in advance for your help :)
Answer by ju_my · Feb 22, 2020 at 09:16 PM
Maybe the upgrade function should just keep the same GameObject but only change aspect and values you want to change at upgrade?
Yeah that is my last way out but ive made slight changes to the different models so I most of all want to use them if thats not possible i have to just change values
Answer by ashkanaral · Feb 22, 2020 at 09:37 PM
Try creating more methods OR create parameters.
Well I was thinking bout that earlier too but that's soo much code and things to think of I was hoping for something more like, newTurret.GetComponent() = oldTurret.GetComponet(); obviously it's not that simple but something similar
I think you are trying to do something similar to this guys question. Look at my answer. It may work.
Don't forget you can duplicate your scene so your values won't get changed on the inspector or Copy and paste all your hierarchy into new scene.
Thats not exactly what i searched for but i think ive solved it now by just creating a new method that sets all the variables form the old script to the new script its like 10 variables or so but it should work fine, thanks for you help! :)