Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
Debug.Log("OnTriggerEnter() was called");
if (other.tag  == "Coin") {
    Debug.Log("Other object is a coin");
    score += 10;
    scoreText = "Score: " + score;
    Debug.Log("Score is now " + score);
    Destroy(other.gameObject);



There is always an error every time I put if(other.tag == "Coin") in c#

[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 14-Dec-13 21:03pm
v3
Comments
Sergey Alexandrovich Kryukov 15-Dec-13 2:21am    
Where is the Java code?!!
And there is no such thing as "Java script".
—SA
BillWoodruff 15-Dec-13 2:26am    
What's the error message ?

1 solution

The reason is probably that a Tag property is normally an object and an object is not a string, so you can't compare it with one.

Cast the Tag property to the class you are expecting, and use it then:
C#
string s = other.tag as string;
if (s != null & s == "Coin")
   ...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900