- Home /
How to change an object's property from another script
I have three scripts. The first one creates a class Villager. The second script creates an object of class Villager, called villager01, which has a property villager01.health = 1;
In the third script there is a button that, when pressed, should change the health property as follows: villager01.health = villager01.health + 1;
However, Unity is telling me that the name villager01 does not exist in the context. Could somebody please help me out here and tell me how to tell unity about the villager01 object? I'm a beginner when it comes to object oriented programming, so I'm trying to grasp the basics here. :)
Try this small tutorial on accessing variables from different scripts. I wrote it since I saw a lot of questions regarding basics. If something is unclear, please do make a comment below and I can see what I can do to make it clearer.
Your answer
Follow this Question
Related Questions
Object from flash to unity 2 Answers
change property an object when another change 2 Answers
Add custom properties to Objects 1 Answer
How to create Prefab with property 2 Answers