public bool IsValid(GameObject p_owner) { IHasTarget hasTarget = p_owner.GetComponent <IHasTarget>(); Assert.IsNotNull(hasTarget, "This component must implements IHasTarget."); return(hasTarget?.GetTarget() != null); }
public void DoAttack() { if (cooldownTimer <= 0.0f) { var attackTarget = attackerAI.GetTarget(); var destroyable = attackTarget.GetComponent <IDestroyable>(); destroyable.Damage(damage); var body = attackTarget.GetComponent <Rigidbody2D>(); if (body) { //Debug.Log("adding force"); //body.AddForce((transform.position - attackTarget.position).normalized*knockbackForce); body.velocity = (attackTarget.position - transform.position).normalized * knockbackForce; } else { myBody.velocity = -(attackTarget.position - transform.position).normalized * knockbackForce; } cooldownTimer = cooldown; } }