Gameobjects are getting randomly spawned on some platform objects. I want to avoid these two different gameobject to be spawned at the same exact location (money2 should change it’s position).
Here is the code:
void Start()
{
int randMoney = Random.Range(0, 8);
Vector3 moneyPos = transform.position;
moneyPos.y += 0.5f;
if (randMoney < 1)
{
GameObject moneyInstance = Instantiate(money, moneyPos, money.transform.rotation);
moneyInstance.transform.SetParent(gameObject.transform);
}
int randMoney2 = Random.Range(0, 8);
Vector3 money2Pos = transform.position;
money2Pos.y += 0.5f;
if (randMoney2 < 1)
{
GameObject money2Instance = Instantiate(money2, money2Pos, money2.transform.rotation);
money2Instance.transform.SetParent(gameObject.transform);
}
if (money2Pos == moneyPos)
{
//where gameobject2s position should change
}
}
Thank you for taking your time!