Trouble with Coroutine Performance in Profiler

Hello,
well i do this in a Coroutine and get 22.6% in Profiler…
What did i made wrong ?

void DoTargetting() {		
	if (EnemyName == null) 
	EnemyNameX.Text = "No Target";
	 else 
	EnemyNameX.Text = EnemyName; 
	
	if (EnemyDist < 100.0) 
    distanceText.Color = Color.red;
     else 
    distanceText.Color = Color.white;
    	
	distanceText.Text = (EnemyDist.ToString("f2") + " ft") ;
	distogroundText.Text = ("Ground " + GroundDistance.ToString("000") + " ft") ;

	if (GroundDistance < 10.0) {
    GroundWarn.SetToggleState("1");  //Bad : Static Collider.Move (Expensive Delay Cost)
	distogroundText.Color = Color.red;
    } else {
    GroundWarn.SetToggleState("0"); //Bad : Static Collider.Modify (Expensive Delay Cost)
	distogroundText.Color = Color.white;
    }
	}

How can i make the Code better for performance… it’s for Mobile…

Thank you for taking time !

816653--30225--$Bildschirmfoto 2012-01-31 um 23.26.13.PNG

Why are you moving a static collider? Give it a rigidbody and make it kinematic.

Add some profiler tags, using Profiler.Begin(“SomeString”); Profiler.End(). They will add extra blocks in the profiler to start figuring out which functions within that coroutine are expensive.

http://unity3d.com/support/documentation/ScriptReference/Profiler.html

This way you can start drilling down function per function as to what’s costing so much. Those colliders are expensive to move during the Physics Frame, but are only 1/224ths of the time spent in that particular function.

Put Profiler Samples into the functions that cost the most, and continually branch downwards until you get more understandable readings per element, or 1 big value for an unexpected element. I suspect SetToggleState() is doing a lot of work.

Hello,
thx for the reply !
well if i disable the toggle i still have 18%.
Just wonder why if is so expensive and what i can do instead…
thxx