So I’m trying to display an image on these buttons depending on the location they take you to.
I get a out of range error even when I do int ComputedID = ObjectGraphicID[0];
However when I use int ComputedID = ObjectGraphicID.Count;
it says 0 elements but when inspecting the object during run time you can see the list is populated in the component.
ArgumentOutOfRangeException: Argument is out of range.
Parameter name: index
System.Collections.Generic.List`1[System.Int32].get_Item (Int32 index) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Collections.Generic/List.cs:633)
FogOfWarToggle.Start () (at Assets/Scripts/FogOfWarToggle.cs:20)
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
public class FogOfWarToggle : MonoBehaviour {
public bool Fog;
private bool tick;
public int ID;
private string ObjectSprite;
public GameObject TheMatrix; //Number Generator
public List<int> ObjectGraphicID;
public int ComputedID;
// Use this for initialization
void Start () {
ID = gameObject.GetComponent<LocalWarpJump> ().IdMatrix;
ObjectGraphicID = TheMatrix.GetComponent<SolarSystemGenerator>().ObjectGraphicID;
int ComputedID = ObjectGraphicID[ID];
tick = false;
ObjectSprite = ("Planet " + ComputedID);
gameObject.GetComponent<RawImage>().texture = Resources.Load<Texture>(ObjectSprite);
}
// Update is called once per frame
void Update () {
}
public void Button(){
if (tick == false) {
Fog = true;
tick = true;
}else if (tick == true){
Fog = false;
tick = false;
}
}
}