I have a problem how to set a Random object in a polygon without placing it on another object in that polygon
Code is:
public float XSize = 8.7f;
public float ZSize = 8.7f;
public GameObject foodPrefab;
public Vector3 curPos;
public GameObject curFood;
void AddNewFood()
{
RandomPos();
curFood = GameObject.Instantiate(foodPrefab, curPos, Quaternion.identity) as GameObject;
}
void RandomPos()
{
curPos = new Vector3(Random.Range(XSize * -1, XSize), 0.25f, Random.Range(ZSize * -1, ZSize));
}
void Update()
{
if (!curFood)
{
AddNewFood();
}
else
{
return;
}
}
}
↧