I am new to coding and working now on a endless runner game but i dont know what to do to instantiate a game object and spawn it in 3 specifically x axis positions. I tried using Random.Range through arrays but it never works. I dont have an error the program works fine but the gameobject doesn’t spawn the positions i want. I also try arrays with vector3 but then i get an error. Any help would be thankfull
Here is the code i wrote:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CarSpawn : MonoBehaviour
{
public GameObject car;
Vector3 carPos;
float[] xPos = new float[3];
void Start()
{
carPos = new Vector3(Random.Range(xPos[1], xPos.Length), position.y, position.z);
Instantiate(car, carPos, Quaternion.identity);
}
void CarPosition()
{
xPos[1] = -8f;
xPos[2] = 0f;
xPos[3] = 8f;
}
}