public void Feeding_Cycle(ref Animal_Section_SeaUrchin food) { Debug.Log ("eatne food pop" + food.pop); Debug.Log ("feeder food pop" + pop); int pops = pop; int lastindex = 0; //int food_counter = 0 ; if (food.pop >= pops ) { // food_counter = food.pop- pops ; //normal eating (no loss from creature) for (int i =0; i<pops; i++) { lastindex = food.alive.Count - 1; if(lastindex>0){ GameObject.Destroy (food.alive [lastindex]); food.alive.RemoveAt (lastindex); }else if (lastindex ==0){ GameObject.Destroy (food.alive [lastindex]); food.alive[lastindex] = null; } } food.reduce_Death (food.pop - pop,food.death_limit); food.pop = food.pop - pops; food.counter[0] = food.counter[0] - pops; } else if ( food.pop < pops && food.pop >0) { Debug.Log("feed with few sources"); // copepod_class.pop = food.pop - pops; for (int i =0; i<=pops-food.pop; i++) { if(alive.Count >0){ lastindex = alive.Count - 1; if(lastindex>=0){ GameObject.Destroy (alive [lastindex]); alive.RemoveAt (lastindex); }else if (lastindex ==0){ GameObject.Destroy (alive [lastindex]); alive[lastindex] = null; } } } Debug.Log("before while"); while (food.alive.Count >=1){ if(food.alive.Count>2){ GameObject.Destroy (food.alive [0]); food.alive.RemoveAt (0); }else if (food.alive.Count==1){ Debug.Log("last case"); Debug.Log("at last pointer " + food.alive[0]); GameObject.Destroy (food.alive [0]); food.alive[0] = null; } } Debug.Log("after while"); pop = food.pop; counter[0] = pop; counter[1] = 0; Debug.Log("pops " + pops); Debug.Log("food "+food); reduce_Death(pops-food.pop,death_limit ); reduce_Count(pops-food.pop,repro_ratio ); food.pop = 0; food.zeroCounter(); food.zeroDeath(); //food_counter = food.pop - pops; /* for(int i =0; i <=2; i++){ counter[i] = counter[i] - food_counter; if(counter[i]<0) counter[i] = counter[i]*-1; food_counter = food_counter - counter[i]; }*/ }else if(food.pop <=0 && pops>0){ Debug.Log("zero"); for (int i =0; i<pops; i++) { lastindex = alive.Count - 1; if(lastindex>0){ GameObject.Destroy (alive [lastindex]); alive.RemoveAt (lastindex); }else if (lastindex ==0){ //lastindex = alive.Count - 1; GameObject.Destroy (alive [lastindex]); alive[lastindex] = null; } } zeroDeath(); zeroCounter(); pop = 0; } Debug.Log ("pop after eating " + pop); }