示例#1
0
    public override void Start()
    {
        //Add all the sound effects to one object
        soundEffects = GetComponents <AudioSource> ();

        // do baseline start actions first...
        // also grabs default animation component too.
        base.Start();

        // upon first creation, create the common "attackAI" instance
        // Attack = this.gameObject.AddComponent<attackAI>();
        Attack = this.gameObject.GetComponent <attackAI>();

        // What can we attack... Guards and Humans
        // and don't forget about the SafeZone houses too!
        Attack.AddAttackTarget(eNavTargets.Human);
        Attack.AddAttackTarget(eNavTargets.Guard);
        Attack.AddAttackTarget(eNavTargets.SafeZone);

        // When an attack is successful, we call the global event which just scores some points
        // for now, we can do something more specific later on.
        Attack.SuccessfulAttack += (object sender, attackAI.SuccessfulAttackEventArgs e) => globalEvents.OnEnemyElementsHit(gameObject, e.objectHit);

        // via the "Hero Zombie" prefab, it has a child element
        // of "LittleHero_solo" which has animations of
        // L2R_swipe, walk, die, idle_lookaround, hurt
        Attack.AssignAnimation(gameObject, animComponent, "L2R_swipe");

        // Zombies have same default targets of SafeZone and Finish
        // only directly target zombies to safe or finish zones.
        // however, why dont the zombies try to target humans and guards too
        // maybe later
        defaultNavTargets.Clear();
        defaultNavTargets.Add(eNavTargets.SafeZone);
        defaultNavTargets.Add(eNavTargets.Finish);
        // if all else fails, find SOME place in the playable area of the board
        defaultNavTargets.Add(eNavTargets.Playable);


        // Zombies (walk, idle_lookaround, hurt, die, L2R_swipe)
        AnimationClip ac = animComponent.GetClip("idle_lookaround");

        ac.wrapMode = WrapMode.Loop;
        ac          = animComponent.GetClip("hurt");
        ac.wrapMode = WrapMode.Once;
        ac          = animComponent.GetClip("die");
        ac.wrapMode = WrapMode.Once;
        ac          = animComponent.GetClip("L2R_swipe");
        ac.wrapMode = WrapMode.Once;

        // for commonAI during "takeDamage" from attacking
        hasDieAnimation  = true;
        hasHurtAnimation = true;

        completeInit();
    }
示例#2
0
    public override void Start()
    {
        // do baseline start actions first...
        // also grabs default animation component too.
        base.Start();

        // upon first creation, create the common "attackAI" instance
        Attack = this.gameObject.AddComponent <attackAI>();

        Attack.attackInterval = attackInterval;
        Attack.attackRadius   = attackRadius;
        Attack.damage         = attackDamage;

        // What can scary monsters attack... Guards and Humans
        // and don't forget about the SafeZone houses too!
        Attack.AddAttackTarget(eNavTargets.Human);
        Attack.AddAttackTarget(eNavTargets.Guard);
        Attack.AddAttackTarget(eNavTargets.SafeZone);

        // via the "Hero Zombie" prefab, it has a child element
        // of "LittleHero_solo" which has animations of
        // L2R_swipe, walk, die, idle_lookaround, hurt
        Attack.AssignAnimation(gameObject, animComponent, "L2R_swipe");

        // Now, for scaring humans (or whatever else may be scared away.
        CastFear = this.gameObject.AddComponent <castFearAI>();
        CastFear.fearInterval = fearInterval;
        CastFear.fearRadius   = fearRadius;

        // Zombies have same default targets of SafeZone and Finish
        // only directly target zombies to safe or finish zones.
        // however, why dont the zombies try to target humans and guards too
        // maybe later
        defaultNavTargets.Clear();
        defaultNavTargets.Add(eNavTargets.SafeZone);
        defaultNavTargets.Add(eNavTargets.Finish);

        // pick a new target from either safe vs finish possibilities
        moveToNewTarget();

        // Initiate the zombie to walking animation
        //animComponent.wrapMode = WrapMode.Loop;
        //animComponent.Play("walk");
    }
示例#3
0
    public override void Start()
    {
        // do baseline start actions first...
        // also grabs default animation component too.
        base.Start();

        // upon first creation, create the common "attackAI" instance
        Attack = this.gameObject.AddComponent <attackAI>();

        Attack.attackInterval = attackInterval;
        Attack.attackRadius   = attackRadius;
        Attack.damage         = attackDamage;

        // Guard_on_Zombie = GetComponent<AudioSource>();


        Attack.AddAttackTarget(eNavTargets.Human);
        Attack.AddAttackTarget(eNavTargets.Guard);
        Attack.AddAttackTarget(eNavTargets.SafeZone);

        // pass pointer to the one animation object so this and
        // the attack object are working with the same animator and
        // not thinking of them as two separate instances of an animator

        // via the "Hero Guard" prefab, it has a child element
        // of "LittleKnight2_solo" which has animations of
        // R2L_swipe, walk, die, idle_lookaround, idle, hurt
        Attack.AssignAnimation(gameObject, animComponent, "LM_R2L_swipe");

        // if ever moving, look for Zombies or Werewolves.
        // Originally, the java script code was looking for safe-zones and
        // finish entities.  By default, normal targets are safe-zone and finish.
        // however, start by looking for zombies, then move to safe/finish zones
        defaultNavTargets.Clear();
        //defaultNavTargets.Add(eNavTargets.Zombie);
        defaultNavTargets.Add(eNavTargets.Human);
        defaultNavTargets.Add(eNavTargets.Guard);
        defaultNavTargets.Add(eNavTargets.SafeZone);
        defaultNavTargets.Add(eNavTargets.Finish);
        // if all else fails, find SOME place in the playable area of the board
        defaultNavTargets.Add(eNavTargets.Playable);

        // special animation flags uses in commonAI when attacked and dying
        // so as to not duplicate code at this or zombie levels.
        hasHurtAnimation = true;
        hasDieAnimation  = true;

        // Guards (walk, idle, idle_lookaround, hurt, die, R2L_swipe)
        AnimationClip ac = animComponent.GetClip("LM_idle");

        ac.wrapMode = WrapMode.Loop;
        ac          = animComponent.GetClip("LM_idle_lookaround");
        ac.wrapMode = WrapMode.Loop;
        ac          = animComponent.GetClip("LM_hurt");
        ac.wrapMode = WrapMode.Once;
        ac          = animComponent.GetClip("LM_die_collapse");
        ac.wrapMode = WrapMode.Once;
        ac          = animComponent.GetClip("LM_R2L_swipe");
        ac.wrapMode = WrapMode.Once;

        if (stationary)
        {
            // if ever in combat, retain your post if marked as stationary.
            moveAfterCombat = false;

            // default animation is to be idle...
            //animComponent.Play("idle");
        }
        else
        {
            // moving to new target will always initiate walking mode.
            moveToNewTarget();
        }
    }
示例#4
0
文件: zombieAI.cs 项目: kewls74/game1
    public override void Start()
    {
        manaCost = zombieManaCost;

        //StartCoroutine ("updateSpeedbyNearbyZombies");

        lifeSpan = 5000f;
        // do baseline start actions first...
        // also grabs default animation component too.
        base.Start();

        // upon first creation, create the common "attackAI" instance
        // Attack = this.gameObject.AddComponent<attackAI>();
        Attack = this.gameObject.GetComponent <attackAI>();

        // Now, for scaring humans (or whatever else may be scared away.
        // CastFear = this.gameObject.AddComponent<castFearAI>();
        CastFear = this.gameObject.GetComponent <castFearAI>();

        // make sure that the castFear interval is not less than the attack,
        // otherwise every human would be cast "afraid" before a zombie could
        // attack them and turn human into a zombie.
        if (CastFear.fearInterval < Attack.attackInterval)
        {
            // for grins add 1/100 second to delay
            CastFear.fearInterval = Attack.attackInterval + .01f;
        }

        // What can a Zombie attack... Guards and Humans
        // and don't forget about the SafeZone houses too!
        Attack.AddAttackTarget(eNavTargets.Human);
        Attack.AddAttackTarget(eNavTargets.Guard);
        Attack.AddAttackTarget(eNavTargets.SafeZone);

        // Attack successful handler, called when we hit another object.
        // We delegate this directly to the global handler.
        Attack.SuccessfulAttack += (object sender, attackAI.SuccessfulAttackEventArgs e) => globalEvents.OnEnemyElementsHit(sender, e.objectHit);

        // via the "Hero Zombie" prefab, it has a child element
        // of "LittleHero_solo" which has animations of
        // L2R_swipe, walk, die, idle_lookaround, hurt
        Attack.AssignAnimation(gameObject, animComponent, "L2R_swipe");

        // Zombies have same default targets of SafeZone and Finish
        // only directly target zombies to safe or finish zones.
        // however, why dont the zombies try to target humans and guards too
        // maybe later
        defaultNavTargets.Clear();
        defaultNavTargets.Add(eNavTargets.SafeZone);
        defaultNavTargets.Add(eNavTargets.Finish);
        // if all else fails, find SOME place in the playable area of the board
        defaultNavTargets.Add(eNavTargets.Playable);


        // Zombies (walk, idle_lookaround, hurt, die, L2R_swipe)
        AnimationClip ac = animComponent.GetClip("idle_lookaround");

        ac.wrapMode = WrapMode.Loop;
        ac          = animComponent.GetClip("hurt");
        ac.wrapMode = WrapMode.Once;
        ac          = animComponent.GetClip("die");
        ac.wrapMode = WrapMode.Once;
        ac          = animComponent.GetClip("L2R_swipe");
        ac.wrapMode = WrapMode.Once;

        // for commonAI during "takeDamage" from attacking
        hasDieAnimation  = true;
        hasHurtAnimation = true;

        float animSpeed = -.5f;

        animComponent.GetComponent <Animation>() ["die"].speed = animSpeed;

        float animTime = Mathf.Abs(animComponent.GetComponent <Animation>() ["die"].length * (1 / animSpeed));

        animComponent.GetComponent <Animation>() ["die"].time = animComponent.GetComponent <Animation>() ["die"].length;
        animComponent.Play("die");



        Invoke("completeInit", animTime);
    }