using UnityEngine;
using System.Collections;
public class LevelData : MonoBehaviour {
public string nextLevel;
public int objective;
}
Then, in another function, i access this data.
private int count;
private int test;
private string next;
void Start() {
count = levelData.GetComponent<LevelData>().objective;
next = levelData.GetComponent<LevelData>().nextLevel;
winText.text = "";
SetCountText();
}
then i use next here
if (other.gameObject.tag == "Exit") {
Application.LoadLevel(next);
}
}
And it doesn’t work, it takes next as a int. These are the errors i get.
Assets/Scripts/PlayerController.cs(41,73): error CS1061: Type LevelData' does not contain a definition for
nextlevel’ and no extension method nextlevel' of type
LevelData’ could be found (are you missing a using directive or an assembly reference?)
Assets/Scripts/PlayerController.cs(41,37): error CS1502: The best overloaded method match for `UnityEngine.Application.LoadLevel(int)’ has some invalid arguments
Assets/Scripts/PlayerController.cs(41,37): error CS1503: Argument #1' cannot convert
object’ expression to type `int’
I don’t know why it expects int when i pass next who is a String type. Have tried reading the reference and forums but i mostly see JavaScript code. Thanks in advance. For now i’ll just put it as a int.