So I have two characters that can attack each other.
function OnCollisionEnter(collision : Collision)
{
if (canattack)
{
for (var contact: ContactPoint in collision.contacts)
{
var impact = Instantiate(impactPrefab, contact.point, Quaternion.FromToRotation(Vector3.up,contact.normal));
collision.gameObject.SendMessage ("Damage", damage,SendMessageOptions.DontRequireReceiver);
}
}
}
I also have a variable on each player, “isBlocking”. If the player gets hit while he is blocking then the player hitting should be given the “isStunned = true”.
So I did this:
function gotBlocked(damage: float){
isStunned = true;
yield WaitForSeconds(damage/2);
isStunned = false;
}
function Damage(damage : float)
{
if(!isBlocking)
{
health -= damage;
}
else
{
gotBlocked(damage/2);
}
}
But all it does is to apply isStunned to the player that is getting hit. How can i solve this?