Trying to spawn enemies on only one path
I'm using the Simple Waypoint System (an awesome Unity Asset) and I want to have the enemies choose one path and follow the waypoints I've already laid out. The problem is that my path array is a string array and I'm getting an error for trying to convert it to an int. I tried converting the string array to an int array, but then I got an error because I'm referencing a SetPath(PathManager) through the Unity asset that Visual Studio is saying takes 2 arguments. I've tried inserting a second argument, but I'm clearly doing it wrong.
Can anyone tell me what I'm missing here? Here's my code block:
void SpawnEnemy (Transform _enemy) { Debug.Log("Spawning Enemy: " + _enemy.name);
//not sure if this should be a Transform array or something
string[] myPaths = new string[] { "Path1", "Path2", "Path3" };
eMove = _enemy.GetComponent<splineMove>();
//Want to choose Path1, but I'm getting an error
//error: cannot implictly convert type 'string' to 'int'
Instantiate(_enemy, eMove.SetPath(WaypointManager.Paths[myPaths["Path1"]], transform.rotation));
}
you need to access an array with index, for example myPaths[0] will return "Path1", myPaths[1] will return "Path2". Why are you referencing it as myPaths["Path1"]? This is where the compiler is saying it cannot convert string to int.
Your answer
Follow this Question
Related Questions
Spawning limited GameObjects at a specific position not working 1 Answer
Pull int from string if within square brackets 1 Answer
trying to get an Array string to read an Int 0 Answers
Why do I keep getting 'The object you want to instantiate is null' warning? 1 Answer
Spawn prefabs from array in specific order given the size of prefab 1 Answer