- Home /
Problem concerning unit behaviour in Multiplayer RTS
First i have to say, that I'm a beginner at programming. So here is my problem.
My project is an Multiplayer RTS. Right now I try to organise Unit behaviour and Fog of War with a Sphere Collider. I use the Sphere Collider to get units in range and depending on the type of the unit I want to trigger specific behaviour, such as Shoot on Sight.
My idea was to get the unit/building, that isn't parent of the sphere collider and then do with it whatever I want to. In my current code the object just gets hidden when it enters the sight range (should be revealed, but this way it is easier for testing, since both units have the same state and I can better see if only one unit changes its state... easy visual feedback :) ).
void OnTriggerEnter (Collider other) {
if(other.gameObject.name != "Ground") {
Player otherPlayer = other.transform.root.GetComponent<Player>();
if(otherPlayer) {
Unit unit = other.transform.parent.GetComponent<Unit>();
Building building = other.transform.parent.GetComponent<Building>();
if(unit || building) {
HideObject(other.gameObject);
}
}
}
Now the actual problem. Since almost all buildings and units need this script, they all trigger the effect. In most cases this is exactly what I want(f.e. most units should always be able to shoot on sight) , but in my current situation, if two opposing units enter each others sightrange, both hide each other. If you played my game now, you would see your own and the opposing unit be hidden, but only the unit of the opponent should be hidden.
The solution surely would be pretty easy, but since I'm a beginner, I have no clue how to do this.