I know there is quite a few of these questions but i am pretty new on C#/Unity3d and puzzled and confused on why i get the error and how to solve it. I have been reading and testing (try & error) but still do not fully understand why and would appreciate some help.
The code below is the latest test i have done and have been testing quite a few combinations.
using UnityEngine;
using UnityEngine.UI;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Linq;
public class PLACEFromTemplate_Script : MonoBehaviour { //GameEngine_Script {
public PLACEFromTemplate_Script _thePLACEInstance;
// private static Vector3 startPosForPlacing;
// private static Vector3 endPosForPlacing;
// private static bool backSide;
private float scaleOfEnemys;
public static float speedOfPlacingInSeconds = 0.5f;
//==========================================================================//
// //
// ReadTheIncomingTemplateFile //
// //
//==========================================================================//
public void ReadTheIncomingTemplateFile(string TEMPLATE_FILE_NAME) {
_thePLACEInstance = this;
// SHUFFLE THE ENEMY DECK PRIOR TO COPY IT TO THE WORKING LIST
Singleton.Instance.master_GameObject_List = GameEngine_Script.Fisher_Yates_EnemyDeck_Shuffle (Singleton.Instance.master_GameObject_List);
List<EnemyDeck> theEnemysInTheTemplate_List = new List<EnemyDeck> ();
// READ PLACE FILE AND POPULATE THE theEnemyDeck_List
FileStream fs = new FileStream (Application.persistentDataPath + TEMPLATE_FILE_NAME, FileMode.Open, FileAccess.Read);
BinaryFormatter bf = new BinaryFormatter ();
while (fs.CanRead) {
EnemyDeck _EnemyDeck = (EnemyDeck)bf.Deserialize (fs);
if (_EnemyDeck.TheTouch == "EOF")
break;
if (_EnemyDeck.TheTouch == "DECK INITIAL POSITION") {
// SET POSITION FOR THE DECK
PlayerPrefs.SetFloat ("PLACE DECK POS X", _EnemyDeck.PosX);
PlayerPrefs.SetFloat ("PLACE DECK POS Y", _EnemyDeck.PosY);
PlayerPrefs.SetFloat ("PLACE DECK EULER", _EnemyDeck.RotZ);
// SET STARTING POSITION FOR EACH ENEMY PLACE TO THIS
// startPosForPlacing = new Vector3 (_EnemyDeck.PosX, _EnemyDeck.PosY, _EnemyDeck.PosZ);
scaleOfEnemys = _EnemyDeck.ScaleX;
} else {
theEnemysInTheTemplate_List.Add (_EnemyDeck);
print ("Tag: " + _EnemyDeck.EnemyTag);
}
}
// REVERSE THE LIST TO GET THE FIRST ON TOP
theEnemysInTheTemplate_List.Reverse ();
// CALL FUNCTION AND INSTANTIATE THE DECK OF ENEMYS
GameEngine_Script.InstantiateTheDeckOfEnemys(true);
// RUN THE PLACING PROCESS
_thePLACEInstance.StartCoroutine (PLACETheEnemys (theEnemysInTheTemplate_List, Singleton.Instance.master_GameObject_List));
}
static IEnumerator PLACETheEnemys (List<EnemyDeck>theEnemysToPLACE_List, List<GameObject>theEnemys_GameObject_List) {
// COUNT NUMBER OF ENEMYS TO PLACE
int nrOfEnemysToPLACE = theEnemysToPLACE_List.Count - 1;
print ("INIT nrOfEnemysToPLACE: " + nrOfEnemysToPLACE);
while (nrOfEnemysToPLACE > -1) {
yield return new WaitForSeconds (speedOfPlacingInSeconds);
print (theEnemysToPLACE_List[nrOfEnemysToPLACE].EnemyTag + " indx: " + nrOfEnemysToPLACE);
float xPos = theEnemys_GameObject_List[nrOfEnemysToPLACE].transform.position.x;
float yPos = theEnemys_GameObject_List[nrOfEnemysToPLACE].transform.position.y;
float zPos = theEnemys_GameObject_List[nrOfEnemysToPLACE].transform.position.z;
Vector3 startPosForPlacing = new Vector3 (xPos, yPos, zPos);
xPos = theEnemysToPLACE_List[nrOfEnemysToPLACE].PosX;
yPos = theEnemysToPLACE_List[nrOfEnemysToPLACE].PosY;
zPos = theEnemysToPLACE_List[nrOfEnemysToPLACE].PosZ;
Vector3 endPosForPlacing = new Vector3(xPos, yPos, zPos);
bool backSide = theEnemysToPLACE_List[nrOfEnemysToPLACE].BackSideUp;
// ERROR IS HERE
// ERROR IS HERE
// ERROR IS HERE
// ERROR IS HERE
_thePLACEInstance.StartCoroutine (ProcessTheActualEnemy (startPosForPlacing, endPosForPlacing, backSide));
// ===================//
nrOfEnemysToPLACE--;
}
}
static IEnumerator ProcessTheActualEnemy (Vector3 startPos, Vector3 endPos, bool backUp) {
print ("startPos: " + startPos + " endPos: " + endPos + " backUp: " + backUp);
yield return null;
}