How to spawning another cube when i click a cube

i have cube, cube1, triangle, triangle1
if i click cube will show cube1
if i click triangle will show triangle1
but i click cube and i click triangle
it will be show 2 objects.
how to click cube and show cube1
then i click triangle will show triangle1 but cube1 will close automatically

this script same with triangle, just FindChild(“gameobject name is different”)

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Vuforia;

public class fakultassentuh : MonoBehaviour {

    private GameObject obj;

    void Start () {

        obj = transform.FindChild("cube2").gameObject;

        obj.SetActive(false);
 
    }
 
    // Update is called once per frame
    void Update () {
 
    }
    void OnMouseDown(){
        obj.gameObject.SetActive(!obj.gameObject.activeSelf);
    }

}

The problem seems simple but really couldn’t understand your question

Use a Raycast. Either from center screen or mouse position, detect the name or tag of the object that’s hit by the Raycast and if it is the object you want clicked, instantiate a new cube. Call this from something like:

if(GetButton("Fire1"))

i just want click cube and show cube1 and triangle1 will close automatically, not double show
then i click triangle, will show triangle1, then cube1 will close automatically
just 1 show (cube1 or triangle1) but i have double shows when i click cube and triangle


this maybe you understand.

i have 2 box (options) we called box1 and box2…
and box1 will show a cube and box2 will show triangle .
OnMouseDown box1 show cube, OnMouseDown box2 show triangle it work!!
but i want cube will close automatically when box2 pressed and change with triangle.

i have new script but it doesnt work for me. my script will put into Image Target (Augmented Reality project)

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class onclick : MonoBehaviour {

    private GameObject box1;
    private GameObject model1;
    private GameObject box2;
    private GameObject model2;

    void Start () {

        box1 = transform.FindChild("op1").gameObject;
        model1 = transform.FindChild("cube").gameObject;
        box2 = transform.FindChild ("op2").gameObject;
        model2 = transform.FindChild("triangle").gameObject;

        model1.SetActive(false);
        model2.SetActive(false);
    }
   
    // Update is called once per frame
    void Update () {
   
    }

    void OnMouseDown() {
        if (gameObject.name == "box1") {
            model1.gameObject.SetActive(!model1.gameObject.activeSelf);
            model2.SetActive(false);
        }
        if (gameObject.name == "box2") {
            model2.gameObject.SetActive(!model2.gameObject.activeSelf);
            model1.SetActive(false);
            }
    }
}

You could do all of this with a Raycast…