Why is the Object reference is empty ?

Hello, I posted a similar question before, couldnt get an answer. What I am trying to do is a very common thing I believe, and should be easy to solve but somehow I just cant.

Whene I call an instance of script A, in script B, if I try to access its properties, I always get Object reference is null exception, which I dont understand why. Here is one of those places taht I try to do it.

void OnGUI()
{
	if(GUI.Button(new Rect(10,10,100,100),"blas"))
	{
		CameraShooot other = gameObject.GetComponent<CameraShooot>();
		
		if(other != null)
    		other.selectedTexture = (Texture)Resources.Load("ege2");
	}			
}

Would be really happy if someone can tell me what am I doing wrong ? Why ‘other’ variable seems to be null all the time ? If anyone asks, ‘selectedTexture’ is a Texture type public variable which is instatiated with new Texture() and all…

Thanks.

If “other” is null, that means that gameObject.GetComponent<CameraShooot>(); returned null. In other words, that script doesn’t exist on the gameObject.