How would i add additional resource type costs to the towers?

Let’s say I want to make the tower cost 20 wood and 20 iron along with its gold cost. Do i simply duplicate the code and add startingWood, currentWood, woodCost etc or there is a better way of doing that?

Hi Slav,

The best would be to define a new type for your cost. I recommend a struct. Look it up on DotNetPerls or somewhere else. It’s very simple.

In the struct, you define all your resource types.

In your tower, you create an object of that struct type. Then you only have to compare the values in your bank with the values of the struct object of the Tower object. You know how to access the single components of your struct because you know how to access x, y, and z in Vector3, which is also a struct. It works the same.

Did this help? :slight_smile:


See also:

1 Like

Thank you, I wil do that. I didn’t know about DotNetPerls but it looks very helpful!

It’s one of my favourite websites on C#. Very useful if you want to get brief explanations with simple code examples.

2 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms