- Home /
Question by
bmorecareful6 · Nov 20, 2018 at 06:46 AM ·
c#instantiateunity 2d
Need to figure out how to Instantiate going down on the y axis.
I wrote this code to Instantiate object going up on the +y axis. For some reason I can not get the object to Instantiate going down on the -y axis. Any help would be really appreciated.
public GameObject PlayerObj; public GameObject[] ObstaclesArr0;
int obstacleCount;
int playerDistanceIndex = -1;
int obstacleIndex = 0;
int distanceToNext = 30;
void Start ()
{
obstacleCount = ObstaclesArr0.Length;
InstantiateObstacle();
}
void Update ()
{
int PlayerDistance = (int)PlayerObj.transform.position.y / (distanceToNext);
if (playerDistanceIndex != PlayerDistance)
{
InstantiateObstacle();
playerDistanceIndex = PlayerDistance;
}
}
public void InstantiateObstacle()
{
int RandomInt = Random.Range(0, obstacleCount);
GameObject newObstacle = Instantiate(ObstaclesArr0[RandomInt], new Vector3(0, obstacleIndex * distanceToNext), Quaternion.identity);
newObstacle.transform.SetParent(transform);
obstacleIndex++;
}
Comment
Your answer
Follow this Question
Related Questions
Unexpected symbol 'Instantiate' [SOLVED] 1 Answer
Why is my default Z set as -4000? 0 Answers
Instantiated object not showing in scene or hierarchy 2 Answers
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer