fertgadget.blogg.se

Unity game engine math
Unity game engine math












  1. UNITY GAME ENGINE MATH HOW TO
  2. UNITY GAME ENGINE MATH GENERATOR

Int oldOutputValue = outputFieldInfo.GetValue(city) as Integer

unity game engine math

Int inputValue = inputFieldInfo.GetValue(city) as Integer įieldInfo outputFieldInfo = city.GetType().GetField(outputResource) obtaining the value of a variable with the name only known at runtimeįieldInfo inputFieldInfo = city.GetType().GetField(inputResource) This allows you (among other things) to acquire the value of a variable when you have the name of that variable in a string at runtime.Įxample: // these would come from the ScriptableObject The first you might want to look into is a C# feature called reflection. There is a limit to how much you can "soft-code" until your soft-coded logic becomes just as complex as hard-coded logic.īut if you really want to go that route, then I have two alternatives for you. I would really recommend to implement mechanics like this in code.

UNITY GAME ENGINE MATH HOW TO

But I'm stuck on how to do the more complex ones.Īnyone have an idea about how to accomplish something like this? create a scriptable object attached to a primary value (say population) and then a simple modifier. Some of the simpler formulas seems pretty easy, i.e. These are examples, but the formulas should allow for arbitrary interactions with other values in the game.

UNITY GAME ENGINE MATH GENERATOR

A "production" resource generator with the "assigned population * production tech level * 0.75" with a max value of "1000 * city level" where excess production gets dumped to gold.Īnd so on.

unity game engine math

A "research" resource generator with "assigned population * 0.5" as the formula to indicate that, each turn, the population assigned to research generates 0.5 pts of research per person.A "gold" resource generator with the "population * 0.025" formula to indicate that, each turn, the city generates 2.5% of it's population as gold.I'd like to be able to add various "resource generators" at design-time via the inspector with the formula for how the resource is generated per turn.

unity game engine math

What I'd like to do is to be able to create a ScriptableObject and then modify it with the formula and various descriptions (all through the inspector), then add it to the game.Īs an example, my game has cities where each city has several attributes such as population and various technology levels. I am writing a turn-based strategy game and am looking for a way to enable design-time additions of game mechanics where the mechanics each require some different math. Sorry for the title, I did not know how else to describe the question.














Unity game engine math