So I am Building an RTS, Assume I Have average of 200 units Running this processes.
I have 2 involved scripts;
- Targeting Script
- Attacking Script, Name of Script “InfantryClickToMove” I know Stupid name
Currently my attacking script does something that “I thought” was suppose to be very taxing, and that is to getComponenet of target Unit-Stats Script and apply damage to it with every damage tick, assume my attack rate per unit is sub 1 second.
Script That I used:
if (myTargetScriptRefrence.target != null)
{
targetUnitStats = myTargetScriptRefrence.target.gameObject.GetComponent<UnitStats>();
targetUnitStats.damageHealth(currentDamageOutPutValue);
}
Thus I changed it to this:
public UnitStats injectedUnitStats (UnitStats InjectedtargetUnitStats)
{
targetUnitStats = InjectedtargetUnitStats;
return targetUnitStats;
}
if (myTargetScriptRefrence.target != null) //Consider this on Update
{
targetUnitStats = myTargetScriptRefrence.target.gameObject.GetComponent<UnitStats>();
targetUnitStats.damageHealth(currentDamageOutPutValue);
}
And I made it so that my targeting Script, does this every time it changes target:
targetunitStatsReference = target.GetComponent<UnitStats>();
InfantryClickToMoveReference.injectedUnitStats(targetunitStatsReference);
Now heres the Problem, I tried both scripts with 200 units attacking at the same time, and yet, my FPS was the same. but why?? I dont understand
Please help, I am a noob


