Hi all,
I have mada a racing game and in this i have adjusted the car torque’s with the help of a text file…
Now the problem is that when i take a build, how to read that file???
Hi all,
I have mada a racing game and in this i have adjusted the car torque’s with the help of a text file…
Now the problem is that when i take a build, how to read that file???
How exactly do you have the data arranged within the text file? Is it something where you could simply using the StreamReader from the System.IO namespace to read the data, if it is fairly complex, then you may want to look in to class serialization to handle the processing needed to be done.
Yes, i ma using Stream reader to read the data???
Now what should i do???
Now that you have read the data into your script file, you apply it to what ever variables that you need to update with the data from the text file. Maybe I am not fully understanding what you are intending to do with this, perhaps you could post your code and script file along with a slightly more detailed explanation of what you are attempting to do so that the community can better attempt to assist.
Thank you for the reply i will do it…
I am reading a text file named test1 with the help of following code
var fileName = "test1.txt";
function Start ()
{
//var number : int;
var sr = new StreamReader("test1.txt");//(Application.dataPath + "/" + fileName);//("test.txt");//
var fileContents = sr.ReadToEnd();
var s = sr.ReadLine();
sr.Close();
var lines = fileContents.Split("\n"[0]);
for (number in lines)
{
//print (line);
storage[sto] = number;
sto++;
}
}
I am storing the values in an array.
And with the help of that array i am attaching specific torque to the cars.
I want to change the text file at run time and that should affect the game.
For that, where should i get that text file in the build???
From what I am understanding, you are looking to change the text file doing the running of the application and reread the values inside? If that is the case, why not keep the values as variables from when they are first read and then add a method of OnApplicationQuit to contain the code of writing these values back into the text file for reading the next time the application is run. Also if this code is used throughout multiple scenes in your application, you could add a safe singleton pattern to this class so you can call it in any number of scripts without having to include the component ( Though some may correctly argue the point against the use of singletons ). If I am not understanding fully please let me know and I will try my best to further assist.
Thank you for your kind reply alex…
The main problem is that:
I made a racing game between 13 AI cars(No user cars).
For this game, the program should accept a text file and the winning of the cars should be dependent on that file. That is, i gave numbering to each and every car and for example, if my text file contains:
7
3
6
9
10
1
4
8
2
12
5
13
11
These numbers.
Then,
7 number car should complete in first place.
3 number car should complete the race in second place and so on…
I kept that text file in assets and when i am changing the order, it is happening.
But i am unable to figure out how to change that text file when a build is taken…
So when i take a build where exactly can i find that text file to change the order of winning.