I have a code written as the following
void Awake()
{
if(this.robot == null)
this.robot = GameObject.FindObjectOfType<Robot>()as Robot;
else {
this.robot = null;
this.robot = GameObject.FindObjectOfType<Robot>()as Robot;
}
}
Since this is happening in Awake()
, is null checking necessary? Can’t it be written as the following?
void Awake()
{
this.robot = GameObject.FindObjectOfType<Robot>()as Robot;
}
EDIT:
I am not accessing robot’s properties or methods in the Awake().