protected override bool OnDone(GoapAgent agent, WithContext context) { if (context.target.GetType() == typeof(Weed)) { Weed weed = context.target as Weed; if (weed != null && weed.ToString() != "Null" && weed.ToString() != "null") { weed.amount -= eatAmount; } if (weed.amount <= 0) { GameObject weedObj = weed.gameObject; Destroy(weedObj); } } else { Candy candy = context.target as Candy; if (candy != null && candy.ToString() != "Null" && candy.ToString() != "null") { candy.amount -= eatAmount; } if (candy.amount <= 0) { GameObject candyObj = candy.gameObject; Destroy(candyObj); } } if (agent.GetType() == typeof(Dog)) { Dog dog = agent as Dog; dog.wantMoreFood(); } RefreshTargets(); return(base.OnDone(agent, context)); }