Beispiel #1
0
 override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
 {
     Enemy  = animator.gameObject.transform.GetComponentInParent <Enemy_AI>().gameObject;
     player = Enemy.GetComponent <Enemy_AI>().GetPlayer();
     AI     = Enemy.GetComponent <Enemy_AI>();
     OnStateUpdate(animator, stateInfo, layerIndex);
 }
Beispiel #2
0
 void Fire()
 {
     ammunition--;
     audiosource.PlayOneShot(gunshot);
     if (ammunition == 0)
     {
         fire_animation.SetBool("Empty", true);
     }
     else
     {
         fire_animation.SetTrigger("Fire");
     }
     ray = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));
     if (Physics.Raycast(ray, out hit, 100))
     {
         if (hit.transform.gameObject.tag == "enemy")
         {
             Debug.Log("Hit");
             Enemy_AI enemey = hit.transform.gameObject.GetComponent <Enemy_AI>();
             enemey.Hit(25);
         }
         else
         {
             Debug.Log("Miss");
         }
     }
 }
Beispiel #3
0
    private void SpawnMinionWave()
    {
        //GameObject objectToSpawn = _availableEnemyPrefabs[UnityEngine.Random.Range(0, _availableEnemyPrefabs.Count)];
        WaveManager.WavePredictionAI waveData = WaveManager.GetCurrentWave();
        GameObject objectToSpawn = waveData._aitype._aiObjectReference;
        bool       isEnhanced    = WaveManager.GetChanceOfEnhancedAI();

        int toSpawnCount = _waveSize.Random;

        for (int i = 0; i < toSpawnCount; i++)
        {
            Vector3    spawnPos   = _spawnLocation.position + (Vector3.up * objectToSpawn.transform.localScale.y * 1.1f) * i;
            GameObject waveObject = Instantiate(objectToSpawn, spawnPos, _spawnLocation.rotation);
            Enemy_AI   aiRef      = waveObject.GetComponent <Enemy_AI>();
            if (aiRef == null)
            {
                Debug.LogErrorFormat(waveObject, "Could not find reference to 'AI' script on object {0}", waveObject.name);
                continue;
            }

            aiRef.InitialiseAI(new object[] { spawnPos }, waveData._combatType);

            if (isEnhanced)
            {
                Debug.Log("I am enhancing DA AI");
                aiRef.EnhanceAI();
            }
        }
    }
Beispiel #4
0
    public void Use(GameObject user)
    {
        Enemy_AI        aI           = GameObject.Find("Enemy").GetComponent <Enemy_AI>();
        CoolDownManager aiCDMaganger = GameObject.Find("Enemy").GetComponent <CoolDownManager>();
        Skill           ba           = new BasicAttack();

        if (user == GameObject.Find("Player") && !Skill_Handler.isBroken && skill_Handler.QSlot.cdEnd && skill_Handler.state == Skill_Handler.ButtonState.qActive)
        {
            playerShot = true;
            BulletDirection thisBullet = Instantiate(Bullet, firepoint.position, Quaternion.identity);
            thisBullet.gameObject.name = "PlayerBullet";

            skill_Handler.QSlot.CoolDownCounter(CreatePlayer.chosenShip.QSkill, skill_Handler.qSkillSlot);
        }

        if (user == GameObject.Find("Enemy") && !aI.isBroken && cdEnd)
        {
            BulletDirection thisBullet = (BulletDirection)Instantiate(Bullet, firepoint.position, Quaternion.identity);
            thisBullet.transform.rotation = Quaternion.Euler(0, 180f, 0);
            thisBullet.gameObject.name    = "EnemyBullet";
            thisBullet.EnemyShot();

            if (Circle_Move_Behaviour.enemyCircleMove)
            {
                ba.SkillCoolDown = 1;
            }

            StartCoroutine(SimpleCoolDown(CreateEnemy.EnemyShip.QSkill.SkillCoolDown));
        }
    }
Beispiel #5
0
    // Update is called once per frame
    public void UpdateTarget()
    {
        GameObject[] enemies = GameObject.FindGameObjectsWithTag(enemyTag);

        float ShortestDistance = Mathf.Infinity;

        GameObject nearestEnemy = null;

        foreach (GameObject enemy in enemies)
        {
            float distanceToEnemy = Vector3.Distance(transform.position, enemy.transform.position);
            if (distanceToEnemy < ShortestDistance)
            {
                ShortestDistance = distanceToEnemy;
                nearestEnemy     = enemy;
            }
        }
        if (nearestEnemy != null && ShortestDistance <= range)
        {
            target      = nearestEnemy.transform;
            targetEnemy = nearestEnemy.GetComponent <Enemy_AI>();
        }
        else
        {
            target = null;
        }
    }
Beispiel #6
0
    private void Attack()
    {
        Vector3 dir = (target.transform.position - transform.position).normalized;

        float distance = Vector3.Distance(target.transform.position, transform.position);

        float direction = Vector3.Dot(dir, transform.forward);

        if (distance < range)
        {
            if (direction > 0)
            {
                Enemy_AI ea = (Enemy_AI)target.GetComponent("Enemy_AI");
                Enemy_health_tracking eh = (Enemy_health_tracking)target.GetComponent("Enemy_health_tracking");

                if (ea.isFollowing == false)
                {
                    eh.curHealth = 0;
                }
                else
                {
                    eh.AddjustCurentHealth(-10);
                }
            }
        }
    }
 private void Awake()
 {
     enemyRef      = GetComponentInParent <Enemy_AI>();
     playerHPref   = target.GetComponentInParent <Player_Health>();
     playerRBref   = target.GetComponentInParent <Rigidbody>();
     playerMoveRef = target.GetComponent <Player_Movement>();
 }
Beispiel #8
0
    public void OnTriggerEnter2D(Collider2D target)
    {
        string enemy = target.name;

        if (enemy == "Enemy" && PlayerShot == true)
        {
            Enemy_AI AI = target.gameObject.GetComponent <Enemy_AI>();
            if (!AI.isBroken)
            {
                StartCoroutine(AI.BrokenAI(8));
            }
            gameObject.GetComponent <Renderer>().enabled   = false;
            gameObject.GetComponent <Collider2D>().enabled = false;
            Destroy(gameObject, 10);
        }
        if (enemy == "Player" && PlayerShot == false)
        {
            Skill_Handler allSlots = target.gameObject.GetComponent <Skill_Handler>();
            if (!Skill_Handler.isBroken)
            {
                allSlots.Broken(10);
            }
            gameObject.GetComponent <Renderer>().enabled = false;
            Destroy(gameObject, 10);
        }
    }
Beispiel #9
0
 private void Awake()
 {
     agent       = GetComponent <UnityEngine.AI.NavMeshAgent>();
     enemyAI     = GetComponent <Enemy_AI>();
     fireMask    = LayerMask.GetMask("Fire");
     playerMask  = LayerMask.GetMask("Player");
     target      = GameObject.FindGameObjectWithTag("Player");
     agent.speed = speed;
 }
    void Update()
    {
        Enemy_AI ea = (Enemy_AI)GetComponent("Enemy_AI");

        if (isTouched == true)
        {
            ea.isFollowing = true;
        }
    }
Beispiel #11
0
    private void AddNewEnemyAIInternal(Enemy_AI newAI)
    {
        if (_enemyAI.Contains(newAI))
        {
            return;
        }

        _enemyAI.Add(newAI);
    }
Beispiel #12
0
    private void Damage(Transform enemy)
    {
        Enemy_AI EN = enemy.GetComponent <Enemy_AI>();

        if (EN != null)
        {
            EN.TakeDamage(damage);
            Destroy(this.gameObject);
        }
    }
Beispiel #13
0
    private void Start()
    {
        AI     = GetComponent <Enemy_AI>();
        player = GameObject.FindGameObjectWithTag("Player").GetComponent <Player>();

        if (broadcastExistence)
        {
            GameManager.instance.conditionsCount++;
        }
    }
Beispiel #14
0
    private void RemoveEnemyAIInternal(Enemy_AI toRemove)
    {
        if (!_enemyAI.Contains(toRemove))
        {
            return;
        }

        _enemyAI.Remove(toRemove);
        55        EvaluateEnemies();
    }
    public void Start()
    {
        WP = GameObject.FindWithTag("WayPoints").GetComponent <WayPoints>();
        WS = GameObject.FindWithTag("GM").GetComponent <WaveSpawner>();
        ST = GameObject.FindWithTag("GM").GetComponent <PlayerStats>();

        target = WP.wpoints[0];

        EN = this.gameObject.GetComponent <Enemy_AI>();
    }
Beispiel #16
0
 void Start()
 {
     tapToStart         = GameObject.FindGameObjectWithTag("C1").GetComponent <TapToStart>();
     isbu               = false;
     isfu               = false;
     playerBreak        = false;
     isDead             = false;
     enemy_AI           = GameObject.Find("Enemy").GetComponent <Enemy_AI>();
     isPlayerWon        = false;
     player_Rigidbody   = GetComponent <Rigidbody>();
     isJumpLimitReached = false;
 }
Beispiel #17
0
    // OnTriggerEnter is called when the Collider other enters the trigger
    public void OnTriggerEnter(Collider other)
    {
        if (other.tag == "Pushable")
        {
            BoomBox bb = other.GetComponent <BoomBox>();
            if (bb == null)
            {
                return;
            }

            if (bb.chargedUp)
            {
                return;
            }

            //maybe apply force on the point of impact? not quite easy to get with trigger
            Vector3   dir = other.transform.position - this.transform.position;
            Rigidbody boomBoxRigidBody = other.GetComponent <Rigidbody>();

            //could consider these:

            /*
             * boomBoxRigidBody.AddForceAtPosition
             * boomBoxRigidBody.AddExplosionForce
             */

            //old version: impact force higher the closer the object is to the impact point
            //boomBoxRigidBody.AddForce(dir.normalized * (Mathf.Abs((1 - dir.magnitude / impactSize)) / maxRadius) * forceModifier, ForceMode.Impulse);

            //new version: forced is the same for every object, determined by the blast radius
            boomBoxRigidBody.AddForce(dir.normalized * impactSize, ForceMode.Impulse);

            if (doDamage)
            {
                bb.ChargeUp(redWave);
            }
        }
        else if (other.tag == "enemy")
        {
            Enemy_AI enem = other.GetComponent <Enemy_AI>();
            if (enem.redEnemy == this.redWave)
            {
                if (doDamage)
                {
                    enem.Stun();
                }
                else
                {
                    other.GetComponent <Rigidbody>().AddForce((other.transform.position - this.transform.position).normalized * impactSize, ForceMode.Impulse);
                }
            }
        }
    }
Beispiel #18
0
    void Start()
    {
        Physics2D.IgnoreLayerCollision(0, 16);

        jumpSound       = GetComponent <AudioSource>(); // assign AudioSource
        monsterDieSound = GetComponent <AudioSource>(); // assign AudioSource
        landingSound    = GetComponent <AudioSource>(); // assign AudioSource
        deathSound      = GetComponent <AudioSource>(); // assign AudioSource

        _player_health = FindObjectOfType <Player_Health>();
        _score_manager = FindObjectOfType <ScoreManager>();
        _score_manager = FindObjectOfType <ScoreManager>();
        enemyAI        = FindObjectOfType <Enemy_AI>();

        monsterPoints = 50;
        duckPoints    = 100;
        howIsMerry    = 1;  // alive
    }
Beispiel #19
0
    // Update is called once per frame
    void Update()
    {
        enemyCurrentPos = enemyAi.gameObject.transform.position;



        if (enemyAi.gameObject == null)
        {
            enemyAi = GameObject.Find("Enemy").GetComponent <Enemy_AI>();
        }



        if (enemyAi.isDead == true)
        {
            StartCoroutine("EnemyInitialize");
            enemyAi.isDead = false;
        }
    }
Beispiel #20
0
    public void CanSee()
    {
        Enemy_AI ea = (Enemy_AI)GetComponent("Enemy_AI");

        targetDir = -myTrans.position + ea.target.transform.position;

        targetRay = new Ray(myTrans.position, targetDir);
        if (Physics.Raycast(targetRay, out hit))
        {
            if (hit.collider.tag == "Player")
            {
                canSee = true;
            }
            else
            {
                canSee = false;
            }
        }

        Debug.DrawRay(myTrans.position, targetDir, Color.red);
    }
Beispiel #21
0
    public void Trigger()
    {
        CanSee();

        Enemy_AI ea = (Enemy_AI)GetComponent("Enemy_AI");

        Vector3 dir = (ea.target.transform.position - transform.position).normalized;

        if (Vector3.Distance(ea.target.transform.position, myTrans.position) < ea.maxDistance && Vector3.Dot(dir, transform.forward) > 0)
        {
            if (myTrans.position.y < target.position.y + 5 && myTrans.position.y > target.position.y - 5 /*&& canSee == true*/)
            {
                ea.isFollowing = true;
            }
        }

        if (Vector3.Distance(ea.target.transform.position, myTrans.position) > ea.maxDistance)
        {
            ea.isFollowing = false;
        }
    }
Beispiel #22
0
    void Spawn()
    {
        dist = 10;
        //adjust spawn number
        if (spawns > 0)
        {
            //obj = GameObject.CreatePrimitive(PrimitiveType.Plane);
            sprite     = Instantiate(GameObject.FindGameObjectWithTag("Enemy"));
            sprite.tag = "Child_Enemy";
            vec.x      = Random.Range(2.3f, 15f);
            vec.y      = gameObject.transform.position.y;
            rand_num   = (int)Mathf.Floor(UnityEngine.Random.Range(0f, 2f));
            if (rand_num == 0 && gameObject.transform.position.z > .5)
            {
                dist *= -1;
            }
            vec.z = gameObject.transform.position.z + dist;
            sprite.transform.position = vec;
            vec.x = 10;
            vec.y = -90f;
            vec.z = 0;

            sprite.transform.rotation = Quaternion.Euler(vec);
            Rigidbody   rb = sprite.AddComponent <Rigidbody>();
            BoxCollider BC = sprite.AddComponent <BoxCollider>();
            vec     = BC.size;
            vec.x   = 1.21f;
            vec.z   = 1.5f;
            BC.size = vec;
            //BC.isTrigger = true;
            //sprite.AddComponent<BoxCollider2D>();
            sprite.transform.parent = null;
            Enemy_AI E_AI = sprite.AddComponent <Enemy_AI>();
            rb.mass           = 5;
            rb.freezeRotation = true;
            //obj.transform.Rotate(vec, Time.deltaTime*10f);
            spawns--;
        }
    }
Beispiel #23
0
    private void SpawnBossWave()
    {
        WaveManager.WavePredictionAI?bossType = WaveManager.GetCurrentBossWave();
        if (bossType == null)
        {
            return;
        }

        GameObject bossToSpawn = bossType.Value._aitype._aiObjectReference;
        Vector3    spawnPos    = _spawnLocation.position + (Vector3.up * bossToSpawn.transform.localScale.y * 1.1f);
        GameObject bossObj     = Instantiate(bossToSpawn, spawnPos, _spawnLocation.rotation);
        Enemy_AI   aiRef       = bossObj.GetComponent <Enemy_AI>();

        if (aiRef == null)
        {
            Debug.LogErrorFormat(bossObj, "Could not find reference to 'AI' script on object {0}", bossObj.name);
        }
        else
        {
            // Passing in NULL for Combat Type because its already assigned within the Boss specifically
            aiRef.InitialiseAI(new object[] { spawnPos }, null);
        }
    }
Beispiel #24
0
    public void Use(GameObject user)
    {
        Enemy_AI aI = GameObject.Find("Enemy").GetComponent <Enemy_AI>();

        if (user == GameObject.Find("Player") && !Skill_Handler.isBroken && skill_Handler.WSlot.cdEnd && skill_Handler.state == Skill_Handler.ButtonState.wActive)
        {
            Missile newMissile = (Missile)Instantiate(MissilePrefab, firepoint.position, Quaternion.identity);
            newMissile.gameObject.name = "PlayerMissile";
            StartCoroutine(newMissile.GetOutState(Enemy));

            skill_Handler.WSlot.CoolDownCounter(CreatePlayer.chosenShip.WSkill, skill_Handler.wSkillSlot);
        }
        if (user == GameObject.Find("Enemy") && !aI.isBroken && cdEnd)
        {
            Skill   sm          = new SteeringMissile();
            Missile thisMissile = (Missile)Instantiate(MissilePrefab, MissilePoint.position, Quaternion.identity);
            thisMissile.gameObject.name    = "EnemyMissile";
            thisMissile.transform.rotation = Quaternion.Euler(0, 180f, 0);
            thisMissile.EnemyShot();
            StartCoroutine(thisMissile.GetOutState(GameObject.Find("Player")));
            StartCoroutine(SimpleCoolDown(CreateEnemy.EnemyShip.WSkill.SkillCoolDown));
        }
    }
Beispiel #25
0
    void OnGUI()
    {
        GameObject go = GameObject.FindGameObjectWithTag("Player");

        ally_targeting at = (ally_targeting)go.GetComponent("ally_targeting");

        Enemy_AI ea = (Enemy_AI)me.GetComponent("Enemy_AI");

        if (Vector3.Distance(me.transform.position, at.gameObject.transform.position) <= ea.maxDistance * 2)
        {
            if (at.targets.Count == 1)
            {
                if (me.transform == at.targets[0])
                {
                    healthBarLength = (Screen.width / 2) * (curHealth / (float)maxHealth);
                    healthBarPlace  = 10;

                    GUI.DrawTexture(new Rect((Screen.width - Screen.width / 2) + 90, healthBarPlace + 40, healthBarLength - 100, 20), healthBarColor);
                    GUI.DrawTexture(new Rect((Screen.width - Screen.width / 2), healthBarPlace, Screen.width / 2, 60), horizontalHealthBar);
                }
            }

            if (at.targets.Count == 2)
            {
                if (me.transform == at.targets[0])
                {
                    healthBarLength = (Screen.width / 2) * (curHealth / (float)maxHealth);
                    healthBarPlace  = 10;

                    GUI.DrawTexture(new Rect((Screen.width - Screen.width / 2) + 90, healthBarPlace + 40, healthBarLength - 100, 20), healthBarColor);
                    GUI.DrawTexture(new Rect((Screen.width - Screen.width / 2), healthBarPlace, Screen.width / 2, 60), horizontalHealthBar);
                }
                if (me.transform == at.targets[1])
                {
                    healthBarLength = (Screen.width / 3) * (curHealth / maxHealth);
                    healthBarPlace  = 70;

                    GUI.DrawTexture(new Rect((Screen.width - Screen.width / 3) + 60, healthBarPlace + (40 - 15), healthBarLength - 65, 15), healthBarColor);
                    GUI.DrawTexture(new Rect((Screen.width - Screen.width / 3), healthBarPlace, Screen.width / 3, 40), horizontalHealthBar);
                }
            }

            if (at.targets.Count == 3)
            {
                if (me.transform == at.targets[0])
                {
                    healthBarLength = (Screen.width / 2) * (curHealth / (float)maxHealth);
                    healthBarPlace  = 10;

                    GUI.DrawTexture(new Rect((Screen.width - Screen.width / 2) + 90, healthBarPlace + 40, healthBarLength - 100, 20), healthBarColor);
                    GUI.DrawTexture(new Rect((Screen.width - Screen.width / 2), healthBarPlace, Screen.width / 2, 60), horizontalHealthBar);
                }
                if (me.transform == at.targets[1])
                {
                    healthBarLength = (Screen.width / 3) * (curHealth / maxHealth);
                    healthBarPlace  = 70;

                    GUI.DrawTexture(new Rect((Screen.width - Screen.width / 3) + 60, healthBarPlace + (40 - 15), healthBarLength - 65, 15), healthBarColor);
                    GUI.DrawTexture(new Rect((Screen.width - Screen.width / 3), healthBarPlace, Screen.width / 3, 40), horizontalHealthBar);
                }
                if (me.transform == at.targets[2])
                {
                    healthBarLength = (Screen.width / 4) * (curHealth / maxHealth);
                    healthBarPlace  = 120;
                    GUI.DrawTexture(new Rect((Screen.width - Screen.width / 4) + 45, healthBarPlace + 20, healthBarLength - 55, 10), healthBarColor);
                    GUI.DrawTexture(new Rect((Screen.width - Screen.width / 4), healthBarPlace, Screen.width / 4, 30), horizontalHealthBar);
                }
            }

            if (at.targets.Count > 4)
            {
                if (me.transform == at.targets[0])
                {
                    healthBarLength = (Screen.width / 2) * (curHealth / (float)maxHealth);
                    healthBarPlace  = 10;

                    GUI.DrawTexture(new Rect((Screen.width - Screen.width / 2) + 90, healthBarPlace + 40, healthBarLength - 100, 20), healthBarColor);
                    GUI.DrawTexture(new Rect((Screen.width - Screen.width / 2), healthBarPlace, Screen.width / 2, 60), horizontalHealthBar);
                }
                if (me.transform == at.targets[1])
                {
                    healthBarLength = (Screen.width / 3) * (curHealth / maxHealth);
                    healthBarPlace  = 70;

                    GUI.DrawTexture(new Rect((Screen.width - Screen.width / 3) + 60, healthBarPlace + (40 - 15), healthBarLength - 65, 15), healthBarColor);
                    GUI.DrawTexture(new Rect((Screen.width - Screen.width / 3), healthBarPlace, Screen.width / 3, 40), horizontalHealthBar);
                }
                if (me.transform == at.targets[2])
                {
                    healthBarLength = (Screen.width / 4) * (curHealth / maxHealth);
                    healthBarPlace  = 120;
                    GUI.DrawTexture(new Rect((Screen.width - Screen.width / 4) + 45, healthBarPlace + 20, healthBarLength - 55, 10), healthBarColor);
                    GUI.DrawTexture(new Rect((Screen.width - Screen.width / 4), healthBarPlace, Screen.width / 4, 30), horizontalHealthBar);
                }
                if (me.transform == at.targets[3])
                {
                    healthBarLength = Screen.height / 3;
                    healthBarPlace  = 155;

                    GUI.DrawTexture(new Rect((Screen.width - (25 + 25 / 3) + 7), healthBarPlace + 25, 15 + 15 / 3 - 3, healthBarLength - 35), healthBarColor);
                    GUI.DrawTexture(new Rect((Screen.width - (35 + 35 / 3)), healthBarPlace, 30 + 30 / 3, Screen.height / 3), verticalHeathBar);
                }
            }
        }
    }
Beispiel #26
0
 public static void AddEnemy(Enemy_AI enemy)
 {
     activeEnemies.Add(enemy);
 }
Beispiel #27
0
 public static void RemoveEnemy(Enemy_AI enemy)
 {
     activeEnemies.Remove(enemy);
 }
 // Start is called before the first frame update
 void Start()
 {
     skill_Handler = GameObject.Find("Player").GetComponent <Skill_Handler>();
     aI            = GameObject.Find("Enemy").GetComponent <Enemy_AI>();
 }
Beispiel #29
0
 void Start()
 {
     enemyAi = GameObject.Find("Enemy").GetComponent <Enemy_AI>();
 }
 public override void OnStateEnter(Animator animator, AnimatorStateInfo animatorStateInfo, int layerIndex)
 {
     enemyAI = animator.GetComponentInParent <Enemy_AI>();
 }