- Home /
Changing game object based on variable state?
For example: I have equipped an item named hammer. On the floor there is an item named iron. If I use my hammer on it, the item on the floor changes to something else.
The items on the floor are prefabs that I've manually placed in my scenes. They each have a script with variables for tracking what other items have been used on them. So I would like for this item on the floor to change based on the variables in its script. How could I select a different prefab based on a variable, then maybe delete the old prefab and instantiate the new prefab at the same location?
Another possibility I thought of is just changing the item's mesh based on the variable? Because I mainly just need the visual to change, I could work around everything else. This seems easier, but would the results be janky if I'm changing an items mesh to a completely different mesh?
Answer by MarekRimal · Apr 10 at 03:35 PM
I would probably just make a prefab which has the script in the parent and has different meshes/models as a children. Then you can just use GameObject.SetActive()
to select the one you currently want.
Your answer
Follow this Question
Related Questions
How can i assign prefab to variable without drag & drop from project to inspector. 2 Answers
setting the text of an instantiated prefab's child's guitext object 1 Answer
How to force a variable to prefab 1 Answer
How to access a variable from a game object once instantiated (C#) 1 Answer
[Solved]Instantiating prefab from a script and destroy it from another one 2 Answers