'Instantiating an object to the position of another vector, hoping to change Y-axis in the code
I have enemies spawn by instantiating them and having them follow a straight path along the X-axis. When instantiated, I want some variability in their height to match the game background.
Instantiate(enemyPrefabs[5], waveConfigs[0].GetWayPoints()[0].transform.position, Quaternion.identity);
yield return new WaitForSeconds(.3f);
Here is my code, I am hoping to have the same transform position called, but to be able to edit the y axis of the transform.position
.
Solution 1:[1]
Something like that your waveConfigs could have two float fields for minYOffset and maxYOffset.
Vector3 spawnerPosition = waveConfigs[0].GetWayPoints()[0].transform.position;
spawnerPosition.y += Random.Range(waveConfigs[0].minYOffset, waveConfigs[0].maxYOffset);
Instantiate(prefab, spawnerPosition, Quaternion.identity, null);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Juri Knauth |