So i have a text file that is
0:
PT:
7
X:
8
Y:
0
Z:
-4.5
RX:
-1.795997E-07
RY:
2.760271E-07
RZ:
2.96859E-09
Summon
1:
PT:
7
X:
18
Y:
-7.105427E-15
Z:
-4.5
RX:
-5.229958E-08
RY:
-1
RZ:
-8.977948E-07
Summon
when it’s paired with the script below they’re supposed to instantiate objects into a scene, every time “Summon” is read via streamreader, but non of the values get set for some reason X,Y,Z of the position and RX,RY,RZ to set the rotation of the object.
0:
PT:
7
X:
8
Y:
0
Z:
-4.5
RX:
-1.795997E-07
RY:
2.760271E-07
RZ:
2.96859E-09
Summon
This object is the first one to be loaded, It has prefab type 7, 8,0,-4.5 is the position. And -1.795997E-07, 2.760271E-07, 2.96859E-09 is the rotation. These values are then used to instantiate an object a specific position.
Here is the script
import System.IO;
@header("GUI elements")
var file : String;
var InputText : UnityEngine.UI.InputField;
@header ("Behind The Scenes")
var CurrentLine : String;
var Prefab1 : GameObject;
var Prefab2 : GameObject;
var Prefab3 : GameObject;
var Prefab4 : GameObject;
var Prefab5 : GameObject;
var Prefab6 : GameObject;
var Prefab7 : GameObject;
var PrefabType : int = 0;
var PosX : float = 0.0;
var PosY : float = 0.0;
var PosZ : float = 0.0;
var RotX : float = 0.0;
var RotY : float = 0.0;
var RotZ : float = 0.0;
var PosXString : String = "X:";
var PosYString : String = "Y:";
var PosZString : String = "Z:";
var RotXString : String = "RX:";
var RotYString : String = "RY:";
var RotZString : String = "RZ:";
var PrefabTypeString : String = "PT:";
var LoadSetting : int = 0;
var SummonString : String = "Summon";
var PosXSummon : float = 0.0;
var PosYSummon : float = 0.0;
var PosZSummon : float = 0.0;
var RotXSummon : float = 0.0;
var RotYSummon : float = 0.0;
var RotZSummon : float = 0.0;
var PrefabSummon : int = 0;
function UpdateName () {
file = InputText.text;
}
function ReadFile(file : String){
file = InputText.text;
if(File.Exists(file + ".txt")){
var sr = File.OpenText(file + ".txt");
var line = sr.ReadLine();
while(line != null){
Debug.Log(line); // prints each line of the file
//Add load scripting here.
CurrentLine = line;
if(LoadSetting == 1){
int.TryParse(CurrentLine, PrefabType);
PrefabSummon = PrefabType;
}
if(LoadSetting == 2){
float.TryParse(CurrentLine, PosX);
PosXSummon = PosX;
}
if(LoadSetting == 3){
float.TryParse(CurrentLine, PosY);
PosYSummon = PosY;
}
if(LoadSetting == 4){
float.TryParse(CurrentLine, PosZ);
PosZSummon = PosZ;
}
if(LoadSetting == 5){
float.TryParse(CurrentLine, RotX);
RotXSummon = RotX;
}
if(LoadSetting == 6){
float.TryParse(CurrentLine, RotY);
RotYSummon = RotY;
}
if(LoadSetting == 7){
float.TryParse(CurrentLine, RotZ);
RotZSummon = RotZ;
}
if (CurrentLine == PrefabTypeString){
LoadSetting = 1;
}
if (CurrentLine == PosXString){
LoadSetting = 2;
}
if (CurrentLine == PosYString){
LoadSetting = 3;
}
if (CurrentLine == PosZString){
LoadSetting = 4;
}
if (CurrentLine == RotXString){
LoadSetting = 5;
}
if (CurrentLine == RotYString){
LoadSetting = 6;
}
if (CurrentLine == RotZString){
LoadSetting = 7;
}
if(CurrentLine == SummonString){
}
line = sr.ReadLine();
}
} else {
Debug.Log("Could not Open the file: " + file + " for reading.");
return;
}
}