it could be that GameObject.Find doesnt find inactive objects, at least in the past that used to be the case it seems, based on a quick search. btw Start function has to start with a capital letter, and ive heard GameObject.Find is pretty slow, so it might not be the best way to do things like this while the application is running
i dont have unity on this computer so cant test but try this:
public GameObject b; //this will show up in the inspector of the GameObject that has this script, you need to drop your GameObject b on it there
void Start ()
{
b.active = false;
}
void Update ()
{
if (Input.GetMouseButtonDown(0))
b.active = true;
}
just read this: ‘‘I want game object B to activate or enable when I click game object A with C Sharp script’’
do you mean you have GameObject A in your game, for example a cube, and if mouse cursor is on it and you click, only then you want to activate GameObject B?
Just reference the objects directly or find via tag and not name, GameObject.Find can only search for active objects.
Also it is terrible to use GameObject.find especially in your update.
So either use public GameObject fields to store a reference via the inspector click and drag, do find the objects in your start method and store them in a variable for later use.
in that case, cast a ray from camera to mouse position (there should be plenty of info on how to do it), and if it hits GameObject a and you click, set GameObject b active
He’s would work if on A. If you put his script on object A and look in the inspector, there will be a slot to drag object B onto it. And the script will work on any object you drag into that reference
public GameObject b; //this will show up in the inspector of the GameObject that has this script, you need to drop your GameObject b on it there
void Start ()
{
b.active = false;
}
void Update ()
{
if (Input.GetMouseButtonDown(0))
b.active = true;
}