I’m trying to let the user choose which seed the game will load as their level, but I can’t access the variable for some reason. What am I doing wrong??
public class SeedNumberScript : MonoBehaviour {
public string stringToEdit = "Enter A Seed Number";
void OnGUI() {
stringToEdit = GUI.TextField(new Rect(10, 10, 200, 20), stringToEdit, 25);
if(GUI.Button(new Rect(10,400,1200,100), "Enter The World"))
{
Application.LoadLevel("NewIdeas&Tests");
}
}
}
Second Script
void Start () {
SeedNumberScript.stringToEdit == Random.seed;
for(int z = 0; z < GameHeight; z++)
{
for(int x = 0 ; x < GameWidth; x++)
{
float rnd = Random.value;
if(rnd <0.25f)
{
Instantiate(TileOne, new Vector3(x,0,z), Quaternion.identity);
}
else if(rnd <0.5f)
{
Instantiate(TileTwo, new Vector3(x,0,z), Quaternion.identity);
}
else
{
Instantiate(TileThree, new Vector3(x,0,z), Quaternion.identity);
}
}
}
}
}
I’m trying to access the String in the first scrip with the second script. I keep getting
Only assignment, call, increment, decrement, and new object expressions can be used as a statement
You need to use GetComponent.
GetComponent<SeedNumberScript>().stringToEdit....
First I dont see a reference declared to the other script.
try here for more information on that.
http://docs.unity3d.com/412/Documentation/ScriptReference/index.Accessing_Other_Components.html
but also make sure your doing the right call.
SeedNumberScript.stringToEdit == Random.seed;
the double == means check to see if this is THE SAME AS Random.Seed;
SeedNumberScript.stringToEdit = Random.seed;
This says SET .stringToEdit to Random.Seed;