How can I:
- Get a straight line between two objects.
- Instantiate a new GameObject every x meters on that line, starting with a specified one of the objects.
How can I:
Here is what I would have done :
// Get your "straight line"
Vector3 vector = objectB.transform.position - objectA.transform.position ;
// Instantiate the gameobject every x meters on that line
for( int dist = startingDistanceFromA ; dist < vector.Magnitude ; dist += x )
{
GameObject newGameObject = GameObject.Instantiate( prefab ) ;
newGameObject.transform.position = objectA.transform.position + vector.normalized * dist ;
// Or
// GameObject newGameObject = GameObject.Instantiate( prefab, objectA.transform.position + vector.normalized * dist, Quaternion.identity ) ;
}