String to Text Mesh Problem

I need help in projecting the health values which is in the playerMovement script to another game object which has a TextMesh. Health values is working fine, I have tested in GUI. But am not sure how to use that health values and pass it to the TextMesh [separate game object.]

playerMovement Script:

{

   public int health;

   void Start()

	{       health = 100;
		myTransform = transform;

		myText = GetComponent<TextMesh>();
	}

   void FixedUpdate()		
	{		
	myText.GetComponent<TextMesh>().text = health.ToString();
	}	

        public void DecreaseHealth(int n)
	{
		health-=n;
		if(health<=0)Destroy(gameObject);
	}


}

The quickest and easiest way to create an association between a script and a component is to add a [SerializedField] private or public field and drag in the component/object in the inspector.

    [SerializedField] private TextMesh myText;
    void FixedUpdate()       
    {       
        myText.text = health.ToString();
    }

Other than that, @Jokim was right and calling GetComponent() every fixedUpdate is not a good idea, and you’ve already got the reference from Start.

You don’t show what type of object myText is. If it is a component or GameObject, make sure that the TextMesh is on the same object (in the same inspector as myText). If it is lower down the hierarchy you may want to use GetComponentInChildren(). I hope that helps =D