public void LookForNewTarget(ThievingTarget thieving_target_type) { bool no_thief_target = false; if (thieving_target_type == ThievingTarget.TomatoFruit) { TomatoFruit[] thieving_target_all = FindObjectsOfType <TomatoFruit>(); List <TomatoFruit> thieving_target = new List <TomatoFruit>(); foreach (TomatoFruit tomato in thieving_target_all) { if (tomato.IsRipe()) { thieving_target.Add(tomato); } } if (thieving_target.Count > 0) { TomatoFruit target_fruit = thieving_target[Random.Range(0, thieving_target.Count - 1)]; target = target_fruit.gameObject.transform; currentTarget = target.position; } else { no_thief_target = true; } } else if (thieving_target_type == ThievingTarget.TomatoPlant) { TomatoPlant[] thieving_target = FindObjectsOfType <TomatoPlant>(); if (thieving_target.Length > 0) { TomatoPlant target_fruit = thieving_target[Random.Range(0, thieving_target.Length - 1)]; target = target_fruit.gameObject.transform; currentTarget = target.position; } else { no_thief_target = true; } } else { throw new System.Exception("Unimplemented thieving type: " + thieving_target_type); } if (no_thief_target) { is_done = true; LeaveArea(); } }
void OnTriggerEnter2D(Collider2D coll) { if (coll.gameObject.GetComponent <TomatoPlant>() != null) { TomatoPlant tomato_plant = coll.gameObject.GetComponent <TomatoPlant>(); TomatoFruit[] tomato_fruits = tomato_plant.gameObject.GetComponentsInChildren <TomatoFruit>(); foreach (TomatoFruit tomato in tomato_fruits) { Destroy(tomato.gameObject); } Destroy(tomato_plant.gameObject); thieving_behaviour.LeaveArea(); // LeaveArea(); // is_done = true; } }