How to find out if a variable is equal to zero?

Hello.

What do I need to do so that the code checks whether there is any object in the transform variable?

            if (hit.transform.TryGetComponent(out ObjGrabbles ObjGrabbles))
            {
                if (CameraInt.gameObject = null)
                {

                }
                Debug.Log(hit.transform.name);
            }

My script

Are you struggling with the single equal sign??

Single equal sign is assignment, which won’t work here.

Double equal sign is comparison.

Otherwise, rather than an incomplete random snippet, try this format for asking technical questions:

This is the bare minimum of information to report:

  • what you want
  • what you tried
  • what you expected to happen
  • what actually happened, log output, variable values, and especially any errors you see
  • links to actual Unity3D documentation you used to cross-check your work (CRITICAL!!!)

The purpose of YOU providing links is to make our job easier, while simultaneously showing us that you actually put effort into the process. If you haven’t put effort into finding the documentation, why should we bother putting effort into replying?

1 Like

hey, i saw an error so just typing by, in the if function you need to use two == equal signs, thats how the code checks your variable, single equal sign is used for assigning

1 Like

Yes, thank you. In fact, I already found a solution simply by rewriting the code.