I need to read a text file containing two pieces of information on each line, and use that information to instantiate a prefab at the correct location in a Unity3D game (c# script). The locations are either North, South, East, or West (each a particular vector).
For example, the first line of the text file might read: landmark1, North
In a script, I need to instantiate landmark1 and assign it to case North vector.
The below script is what I've got so far. Basically, I can read from the text file but I don't know how to assign that information to different cases. I'm guessing I need to use an array somehow but I'm not sure how to do that here.
Any help would be appreciated. Thanks!
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using UnityEngine;
using System.Linq;
using System.IO;
using System;
public class Landmarks : MonoBehaviour {
//spawnable prefab gameobjects
public GameObject castle;
// Use this for initialization
void Start()
{
StreamReader reader = new StreamReader(@"C:/Users/.../landmarks.txt"); //insert full path here
String textContents = reader.ReadToEnd();
// string[] dataArray =
for (int i = 0; i < (textContents.Length); i++)
{
//set case if first line = "castle, North" then instantiate object castle at vector 'north';
}
}
}