Why am I getting this error when both properly named classes/scripts are on the same GameObject?

I got a GameObject named “Store UI Panel”.
On “Store UI Panel” I got two script components:

  1. StoreKitEventListener.cs
  2. TOTstoreHUD.cs (my script) that is this:

using UnityEngine;

using System.Collections;

using System.Collections.Generic;

public class TOTstoreHUD : MonoBehaviour {
     public void displayStoreMessage(string msg)
     {
          storeMessageLabel.text = msg;
     }  
}

But when I try to access displayStoreMessage() from with in the productListRequestFailedEvent() function of StoreKitEventListener.cs like this:

 public class StoreKitEventListener : MonoBehaviour
 {	
       void productListRequestFailedEvent( string error )
       {
            TOTstoreHUD.displayStoreMessage(error);
            Debug.Log( "productListRequestFailedEvent: " + error );
       }
 }

I get the following error:

“Assets/Plugins/StoreKit/demo/StoreKitEventListener.cs(50,17): error CS0103: The name `TOTstoreHUD’ does not exist in the current context”.

Why am I getting this error when both properly named classes/scripts are on the same GameObject?

You need a reference from the GameObject to the component. If the component is on the same GameObject then:

TOTstoreHUD totStoreHudComponent = gameObject.GetComponent<TOTstoreHUD >();
totStoreHudComponent .displayStoreMessage(error);

Or

gameObject.GetComponent<TOTstoreHUD >().displayStoreMessage(error);