Question by 
               unity_MqUXLh65dSlrQw · Aug 05, 2018 at 07:55 AM · 
                3drandomgameobjectsrandom.rangerandom spawn  
              
 
              Random Generation problem GameObject
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;
         }
     }
 }
 
               
                 
                -800x600.jpg 
                (966.5 kB) 
               
 
              
               Comment
              
 
               
              Your answer
 
             Follow this Question
Related Questions
Instantiate objects in given range 1 Answer
Use all variables from array (in Random.Range()) 2 Answers
Need help with specifics in Random.Range 1 Answer
how to randomly choose a value from array 3 Answers
Random bitmap generator 0 Answers