-1
private void Start() { 
    Camera cam = (Camera)FindObjectOfType(typeof(Camera)); // see if camera belongs to the type :camera or send null 
        if (cam)
            Debug.Log("Camera object found: " + cam.name);//main camera
        else
            Debug.Log("No Camera object could be found");
}

What is this if(cam) ? Please help me to solve the problem thanks

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • Basically it is trying to check that variable is truthy or not, you can refer this link for more clarity https://stackoverflow.com/questions/38423360/syntax-for-an-if-statement-using-a-boolean – Sunil Lulla Feb 23 '20 at 08:13
  • Also please start adding more details in your question, it will help other to understand further. – Sunil Lulla Feb 23 '20 at 08:13
  • @SunilLulla the question is short and thank you for your ans – miss chan Feb 23 '20 at 08:28

1 Answers1

1

It checks whether the object is null, destroyed or missing.

It's identical to if((bool)cam) or if(cam != null)

You can only do this for objects with type UnityEngine.Object and derived classes, because UnityEngine.Object overrides bool and != operators, you can check the document here: https://docs.unity3d.com/ScriptReference/Object-operator_Object.html

shingo
  • 18,436
  • 5
  • 23
  • 42