I represented this chunk of code:
class Enemy{
int _health;
void Attack(){
Player.GetDamage(25);
}
}
class Player{
int _health;
public void GetDamage(int amount){
_health -= amount;
}
}
in UML like this:
Is it right representation? I am new in UML and don't know if i'm doing things right.
No, this is not correct. The association is wrong. This is only a dependency, which you need to show as dashed arrowed line. A class diagram only shows a static structure (i.e. how the classes relate to each other).
You show the dynamic part of calling in a sequence diagram:
The Actor1
is some automata in the system which triggers the attack.