public void TakeDamage(float damage, float invulnPeriod)
    {
        if (!invulnerable)
        {
            health      -= damage;
            invulnerable = true;

            if (health <= 0f)
            {
                //put what you want on death to happen
                if (me.CompareTag("Player"))
                {
                    PlayerScript script = me.GetComponent <PlayerScript>();
                    script.Death();
                }
                if (me.CompareTag("Mech"))
                {
                    MechScript script = me.GetComponent <MechScript>();
                    script.Death();
                }
                //put tags of other items here
                if (me.CompareTag("Patroller"))
                {
                    PatrolEnemy script = me.GetComponent <PatrolEnemy>();
                    script.Death();
                }
                if (me.CompareTag("Flyer"))
                {
                    FlyingEnemy script = me.GetComponent <FlyingEnemy>();
                    script.Death();
                }
                if (me.CompareTag("Bomber"))
                {
                    BomberEnemy script = me.GetComponent <BomberEnemy>();
                    script.Death();
                }
                if (me.CompareTag("Boss"))
                {
                    BossEnemy script = me.GetComponent <BossEnemy>();
                    script.Death();
                }
            }
            else
            {
                Invoke("RemoveInvuln", invulnPeriod);
            }
        }
    }
Exemple #2
0
    private void RunGOAP()
    {
        var actions = new List <GOAPAction <BomberEnemy> >();

        actions.Add(new GOAPAction <BomberEnemy>
                    (
                        "GoCore",
                        1f,
                        bomber => bomber.currentLife > bomber.maxLife / 2,
                        bomber =>
        {
            BomberEnemy bomberEnemy = this;

            var tempPath = LazyAStar.Run(target, IsTarget, NeightAndDanger, DistanceToCoreNode).ToList();
            for (int i = 0; i < tempPath.Count - 1; i++)
            {
                bomberEnemy.path.Enqueue(tempPath[i].Item2);
            }
            return(bomberEnemy);
        }

                    ));

        actions.Add(new GOAPAction <BomberEnemy>
                    (
                        "AttackCore",
                        0.5f,
                        bomber => bomber.target.nextNodes.First() == NodeConteiner.instance.TargetNode(),
                        bomber =>
        {
            BomberEnemy bomberEnemy = this;
            bomberEnemy.target      = NodeConteiner.instance.TargetNode();
            return(bomberEnemy);
        }

                    ));

        GOAP.Run(this, x => x.target = NodeConteiner.instance.TargetNode(),
                 actions, Heuristic);
    }
Exemple #3
0
    private float Heuristic(BomberEnemy bomber)
    {
        float dist = Vector3.Distance(bomber.transform.position, NodeConteiner.instance.TargetNode().transform.position);

        return(dist);
    }