- Home /
multipe targets
im trying to learn unity.
i have turrets that use a radius, each time a gameobject enters the radius the turret will turn towards it.unfortunately, when there are multiple target the turret gets confused as to who he should target. how do i make the turret aim at the first, and then when its dead ( or leaves) it focuses on the next available target
im using c#
Answer by Simple · Feb 20, 2011 at 12:20 PM
it is rather simple. Here is a template for you:
bool turret_has_target = false; //global var
//following should be in Update func if (!turret_has_target) { //your script for targeting if (/aim succesfull/) turret_has_target = true; } else { //your aim code //in this part check target presence if (/target destoyed or smth else/) turret_has_target = false; }
im getting a message that says bool cant use the target properly also my aimstate is in the a different page, im also using a state machine...how do i compensate? heres the errors Assets/BasicDetect.cs(22,35): error CS1061: Type bool' does not contain a definition for
target' and no extension method target' of type
bool' could be found (are you missing a using directive or an assembly reference?) NullReferenceException: Object reference not set to an instance of an object AimState.Execute(.State$$anonymous$$achine owner)(at Assets/AimState.cs:31) State$$anonymous$$achine.Update() (at Assets/State$$anonymous$$achine.cs:15)
Unfortunately, I cant help you without your code. But truth is nobody wont work with very big pieces of code.