Hello,
I’m working on game. I’m really new to Unity so I have a lot of ideas and questions.
Does anyone have ideas of how to achieve this:
- Randomly generated NPCs
- They each have their own health, energy
- Energy reduces when they walk (so they will need to move around the scene)
- I wanted the player to be able to click on the NPC and a screen of their stats shows up. And when they click “close” it closes the screen.
If you have some tips on how to carry this out, i would really appreciate. So far I’ve watched a lot of tutorials, but I’m finding it hard understanding what they are doing.
I believe the best way to achieve this (in terms of stats and not visuals) is to make a NPC script where on Start you can use Random.Range(float min, float max)
for health and energy.
You can then have a timer using WaitForSeconds(float time)
then call a method Walk()
which you can make where the NPC moves at a random direction and keep moving for x seconds ot steps (depends on your game). Here is a simple template to help you
//you can choose to make this private or public
private float health;
private float energy;
private float min = 1f;//default
private float max = 100f;//default
private float wait_time = 5f;//default
private void Start(){
//set the health and energy
health = Random.Range(min, max);
energy = Random.Range(min, max);
}
private void Update(){
StartCoroutine(BreakAndWalk());
}
//NPC takes a break before walking again
IEnumerator BreakAndWalk(){
yield new return WaitForSeconds(wait_time);
Walk();
}
//walking method
private void Walk(){
//you fill in here
}
Edit: As for number 4, I never personally used UI in that way, but I am sure someone this platform knows.