Question by
Momin1 · Aug 23, 2016 at 09:03 PM ·
c#scripting probleminstantiateforeach
how to instantiate an object each time there is a certain amount of increase in the y position of another object?
hi everyone...i am trying to instantiate an object(x) each time there is an increase in y position(lets say each time the y position increases by 4, INSTANTIATE ) of another object(a ball) OR each time there is a certain amount of increase in vertical distance between the Ball and another obeject(y) which stays on the ground and not move...how can i do any one of these..plz help
Comment
Best Answer
Answer by oStaiko · Aug 23, 2016 at 09:27 PM
public int iY; //Original position
public int dY; //Step for instantiating
public void Start()
{
iY = tranform.position.y; //Set original position
}
public void Update()
{
if (tranform.y > iY + dY)
{
iY += dY; //Reset original position
Instantiate();
}
}