I'm new to programming in general.
With another Script i store in the list "spawnPointC" all gameobjects called spawnPointC that appear from spawning other prefabs.
I want to pick a random GameObject from that list, and store it's position to spawn another object at the same position later.
I've tried some other things, but i don't know what i'm doing.
How would you do it?
1 using System.Collections;
2 using System.Collections.Generic;
3 using UnityEngine;
4
5 public class CspList : MonoBehaviour
6 {
7 public List<GameObject> spawnPointsC;
8 [SerializeField] private GameObject goal;
9
10 void Start()
11 {
12 GameObject spawnIndex = Random.Range(0, spawnPointsC);
13
14 float pointX = spawnIndex.transform.position.x;
15 float pointY = spawnIndex.transform.position.y;
16 float pointZ = spawnIndex.transform.position.z;
17
18 Vector3 pointSpawn = new Vector3(pointX, pointY, pointZ);
19 Instantiate(goal, pointSpawn, Quaternion.identity);
20 }
21 }