- Home /
 
Add 0.5f to Vector.Right on next instantiated object ?
This is a continuation of this question I posted yesterday about instantiating gameobjects based on a random value, I got it to work , but the problem is the gameobjects instantiate on top of each other. I was wondering if it it possible to add about 0.5f to the vector3.right of the NEXT instantiated gameobject after each current gameobject is instantiated.
So if _gold returns the value "1234" , then the script gets the 1, 2, 3, 4 gameobjects from the following array and is instantiating them, 
But the problem is they're on top of each other when i kill the enemy, like this: 
I need that instaniate part of the script to add an extra 0.3f on the next number that's instantiated.
 [SerializeField]
 private int _gold;
 public int _goldmin;
 public int _goldmax;
 public GameObject[] Numbers;
 private void Start()
 {
     Numbers = new GameObject[Resources.LoadAll<GameObject>("numbers").Length];
     Numbers = Resources.LoadAll<GameObject>("numbers") as GameObject[];
 }
 void numbers()
 {
     
     int digits = _gold;
     do
     {
         Instantiate(Numbers[digits % 10], transform.position + Vector3.up * 0.5f, Quaternion.identity);
         digits /= 10;
     } while (digits > 0);
 
              Answer by Hellium · Sep 20, 2017 at 07:55 PM
  int digits = _gold;
  Vector position = transform.position + Vector3.up * 0.5f ;
  do
  {
      Instantiate(Numbers[digits % 10], position, Quaternion.identity);
      digits /= 10;
      position += Vector3.right * 0.5f ;
  } while (digits > 0);
 
              The position works perfectly! Thank you! I just realized that they are being instantiated the opposite as @Arocide mentioned in the previous questions comment. Any idea on how to fix this? They look like this when instantiated:

Never$$anonymous$$d I should've messed around with it before asking that question , I just changed
position += Vector3.right * 0.5f ;
to
position -= Vector3.right * 0.5f ;
And it works perfectly now, thank you so much!!!
Your answer
 
             Follow this Question
Related Questions
XBox Controller Angle of Fire Incorrect 0 Answers
Instantiated Object being auto-deleted 0 Answers
How to instantiate within GameObject 1 Answer
Unity not Instantiating as Prefab 1 Answer