So… I’m trying to change the text of a 3d text object, but for some reason I get an error that I don’t know how to solve!
This error:
error CS1525: Unexpected symbol `=’
on this line :
this.gameObject/EnemyHp.GetComponent<TextMesh>().Text = (currentHealth + "/ " + maxHealth);
I’m very new to c# and scripting in general, so help would be highly appreciated! 
Edit:
The text object is attached to a cube/enemy, same as the script.
this.gameObject/EnemyHp.GetComponent().Text = (currentHealth + "/ " + maxHealth);
you put a / ? change it to a . also it should be .text not .Text
should be :
this.gameObject.EnemyHp.GetComponent().text = (currentHealth + "/ " + maxHealth);
Pecek
2
The documentation says
GetComponent<TextMesh>().text = "Hello World";
You are trying to access “Text” while there is only “text”.
Here is the whole script:
using UnityEngine;
using System.Collections;
public class EnemyHealth : MonoBehaviour
{
public float currentHealth = 100.00f;
public float maxHealth = 100.00f;
public float colorTimer = 0.5f;
public float healthBarLength = 0.0f;
void Start ()
{
healthBarLength = Screen.width / 2;
}
void Update ()
{
if (renderer.material.color == Color.red)
{
StartCoroutine(Farge());
}
this.gameObject/EnemyHp.GetComponent<TextMesh>().text = (currentHealth + "/ " + maxHealth);
}
IEnumerator Farge()
{
yield return new WaitForSeconds(0.07f);
renderer.material.color = Color.white;
}
//GUI.Box(new Rect(10, 10, healthBarLength, 20), currentHealth + "/" + maxHealth);
void ApplyDamage (float damage)
{
renderer.material.color = Color.red;
currentHealth -= damage;
if(currentHealth < 0)
{
currentHealth = 0;
}
if(currentHealth > maxHealth)
{
currentHealth = maxHealth;
}
if(maxHealth < 1)
{
maxHealth = 1;
}
healthBarLength = (Screen.width / 2) * (currentHealth / maxHealth);
if(currentHealth == 0)
{
Death();
}
}
void Death ()
{
Destroy(gameObject);
}
}
