- Home /
Too subjective and argumentative
Component based architecture Unit, AI, Health, Attack
I've read several articles about component-based programming. It's very difficult for me to make such an component-based architecture, because i'm coming from the OOP site.
What i want to achieve: A Unit, that has health, damage, attackRange, detectionRange of enemies etc. This unit spawns and walks to the enemy base. If it detects an enemy, it shall kill the enemy and then continue to walk to enemy base and attack it.
Now i created several components:
Unit - has all the attributes like health armor, damage,...
Health - Reduces the health
Detection - detects enemies with the onTriggerEnter function and notifies the AI to change state in attacking/hunting/walking/dying/waiting mode
AI - handles the states and sets the walking destionation with a NavMeshAgent
Attack - attacks, if in attacking mode
Now on a first look, they are quiet independent, but then they get connected all together and i receive the opposite of a decoupled architecture. The Attack script calls Detection to get the targeted enemy. The Attack script needs the unit to get all the values like damage and attack range. The Attack Script needs the AI to change the state to WalkingMode after killing an enemy...
And this way somehow all scripts are somewhat coupled again and i have to require my script a lot of others: [RequireComponent(typeof(AI),typeof(Unit),typeof(Detection))]
It seems for me pretty impossible to realize my intention in a decoupled way.
How do you realize decoupling? How would you organize this components? Would you create more components? Would you let it, as it is? What am i doing wrong, that i can't get decoupled components?
Whilst this is a great thought-out question which we certainly appreciate here on Answers, this question would be much more suited for the forums. http://forum.unity3d.com/
This would be more suitable for people to discuss and share their thoughts.
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Are there consequences to exceeding Serialization Depth? 0 Answers
How do I dynamically generate scenes? 5 Answers
Several Questions about MVC pattern 0 Answers
Component architecture problem 0 Answers