Beispiel #1
0
    public bool IsValid(GameObject p_owner)
    {
        IHasTarget hasTarget = p_owner.GetComponent <IHasTarget>();

        Assert.IsNotNull(hasTarget, "This component must implements IHasTarget.");

        return(hasTarget?.GetTarget() != null);
    }
Beispiel #2
0
    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;
        }
    }