public virtual C_Food SpawnFood(GameObject FoodPrefab) { Vector3 randVec = GetTankBounds(); Vector3 spawnLoc = transform.position + new Vector3(Random.Range(-1.0f, 1.0f) * randVec.x, Random.Range(-1.0f, 1.0f) * randVec.y, Random.Range(-1.0f, 1.0f) * randVec.z); GameObject newFood = Instantiate(FoodPrefab, spawnLoc, Quaternion.identity); C_Food foodScript = newFood.GetComponent <C_Food>(); return(foodScript); }
void OnTriggerEnter(Collider other) { if (other.tag == "Food") { if (IsHungry) { C_Food foodComp = other.GetComponent <C_Food> (); if (foodComp != null) { Hunger += foodComp.FoodValue; Destroy(other.gameObject); } } } }