Hello friends, first of all im rookie here ! I have lots of question about gathering resources with AI. Let me talk about what i did. My scenario is one or more cow reach food gameobject and gain energy while collide with it. When they start gaining energy, i want decrease food gameobject and when it contain 0 food__ __it must be destroyed. When i run this script there is no change.
I want ;
- Decrease containedfood
2)Increase cow energy when collide - Stop cow when collide ( I need an idea how to stop when collide )
public class Food : MonoBehaviour
{
Cow _cow;
public float containedFood = 100f;
public float currentFood;
//----------------------------------------------------------------
void Start()
{
currentFood = containedFood;
}
//----------------------------------------------------------------
private void Awake()
{
_cow = GameObject.FindObjectOfType<Cow>();
}
//----------------------------------------------------------------
void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.name == "Cow")
_cow.StopCow(); // I want stop cow when enter collision and play eating anim in this section.
}
//----------------------------------------------------------------
void OnCollisionStay(Collision collision)
{
if (collision.gameObject.name == "Cow")
{
if (currentFood > 1 && currentFood < 100)
{
_cow.GainEnergy();
currentFood -= 1;
}
if (currentFood == 0)
Destroy(gameObject);
print(containedFood);
}
}
}