How can I use GameObject.Find with a string and a variable ?

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 ?

currObjString = “ImageTarget/obj” + currObjNum.ToString(); // must convert int to string

This is what I have working:

public int maxObjNum = 1;
public GameObject currObj;
public int currObjNum = 0;
string currObjString ="";

void OnGUI() {
	if (GUI.Button(new Rect((Screen.width-138),(Screen.height/2)-64,128,128),"Click")) {
       if (++currObjNum > maxObjNum)currObjNum = 0;

       currObjString = "Cube" + currObjNum;
	   print (currObjString);
	   currObj = GameObject.Find(currObjString);
       print (currObj.name);
	   Destroy (currObj);
    }

}

I have two cubes called Cube0 and Cube1 and I do see them being destroyed.

Could it be you are trying to find an inactive object? Find does not see inactive objects.

I would go and create a dictionnary of object so that you can play with them even though they are inactive.