Hello, I need help with a project I’m working on. It’s simple but I can’t make it work as I am a complete newbie at programming. I would like to show objects one by one by clicking on two buttons Next/Previous. I named my object obj0, obj1, obj2… and they are children of an object named ImageTarget. Here is the code I wrote:
using UnityEngine;
using System.Collections;
public class Buttons : MonoBehaviour{
public Texture btnPrev;
public Texture btnNext;
public int maxObjNum = 1;
public GameObject currObj;
public int currObjNum = 0;
void OnGUI() {
if (GUI.Button(new Rect(10,(Screen.height/2)-64,128,128),btnPrev)) {
currObj.SetActiveRecursively(false);
}
if (GUI.Button(new Rect((Screen.width-138),(Screen.height/2)-64,128,128),btnNext)) {
currObj.SetActiveRecursively(false);
currObjNum = currObjNum + 1;
if (currObjNum > maxObjNum) {
currObjNum = 0;
}
currObj = GameObject.Find("/ImageTarget/obj" + currObjNum);
currObj.SetActiveRecursively(true);
}
}
}
The GameObject.Find doesn’t work, how can I fix this ?