I got a error CS1525. invalid expression ‘)’
public class killertriangle : MonoBehaviour
{
void Start()
{
}
public int damage = 1;
public float speed;
private void Update()
{
transform.Translate(Vector2.left * speed * Time.deltaTime);
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag(“Player”))
{
// player takes damage .
other.GetComponent<“Player”>().health -= damage;
Debug.Log(other.GetComponent<“Player”>().health);
Destroy(gameObject);
}
}
How can this be fixed?
What even is this.
To get a component you use the Class name, without the speech marks.
Please use code tags: https://discussions.unity.com/t/481379
How to report problems productively in the Unity3D forums:
http://plbm.com/?p=220
Help us to help you.
There actually is a version of GetComponent where you pass in the class name as a string, but the syntax is different, and it’s less performant.
… And it always scared me because it wasn’t compiler-safe.
But I suppose if it’s already there it might serve some handy bridge with text-to-object serialization in some user-facing context.