I’m pretty new to Unity and wanted to make a simple action RPG. What’s the best way to manage player/enemy health/stats? Should I make a single Game Manager for all or is it better to split the player health/stats into it’s own manager and make a script for each enemy prefab I can just change public values with.
I’m also working on have a very limited amount of items so I’m just gonna add a script to each prefab of an item with simple stats like extra health, mana, damage, etc. until I learn more about how I could make items create with a prefix/suffix table of stats. eg. Diablo 2 style
You’d generally want to avoid 1 script doing too much, that makes it easier to make a mistake and harder to debug when something goes wrong. I usually put a health/damage script on each object that can get damaged or do damage. But it really depends on what exactly you’re making and what you’re trying to achieve.
Thanks for the advice, makes a lot of sense for noobs like me to go through a small amount of code trying to find errors in one script instead of one really long one .
I’ve spent almost $100 this past week on assets I thought would do what I’m trying to achieve that didn’t really work so I’m (slowly :P) learning how to do the simple things I want to do via scripting,
The assets should work well (which ones did you get?), you probably just aren’t experienced enough to use them
However you’ve come to the correct conclusion: you don’t need $100 in assets to make a health/damage system.
Have you done some tutorials? They are very helpful for basic scripting and getting a feel for workflow in Unity: https://unity3d.com/learn/tutorials
The main one I thought would work well is called RPGAIO (Unity Asset Store - The Best Assets for Game Making) and even though it seems like a great script from the videos it hasn’t been updated to work on 5.6 yet.
I downgraded and tried it and still couldn’t get it to work the way I wanted (You can edit values for everything in the RPGAIO window, but if you don’t use the included spawner it breaks).
One problem I’ve been at for the past few hours is trying to make prefab clones start small and end up bigger when they pop out of a chest:
See how the first one starts out tiny and stays that way and the next gets bigger instead of making that first one bigger?
It seems like the script I’m using is affecting the prefab instead of each instance of it because the clones start out small and end up bigger and bigger as a whole instead of one by one.
This is what I put in my chest script:
{
GameObject justDropped;
float newScale = Mathf.Lerp(0, 3, Time.time / 5);
if (randomValue <= LootTable[j].dropRarity)
{
Vector3 direction = new Vector3(Random.Range(1, 3), 3, Random.Range(-2, 2));
justDropped = GameObject.Instantiate(LootTable[j].item, transform.position, Quaternion.identity);
justDropped.GetComponent<Rigidbody>().AddForce(direction * Random.Range(50, 100));
justDropped.transform.localScale = new Vector3(newScale, newScale, newScale);
//justDropped.AddComponent<getbigger>(); //here i tried adding a Mathf.Lerp and transform.Scale script and added it to clone via this script but it does the same thing as above
return; //remove this for more items
}
randomValue -= LootTable[j].dropRarity;
Debug.Log("Random Value decreased" + randomValue);
}
}
}
}