Inheritance: MonoBehaviour
Esempio n. 1
0
 public void CheckDeath()
 {
     foreach (GameObject enemy in enemies)
     {
         EnemyMovement testEnemy = enemy.GetComponent <EnemyMovement>();
         EnemyDeath    death     = enemy.GetComponent <EnemyDeath>();
         if (testEnemy.health <= 0)
         {
             ui.totalMoney += testEnemy.money;
             if (death.spawn != null)
             {
                 for (int i = 0; i < death.amountOfEnemies; i++)
                 {
                     GameObject spawn = Instantiate(death.spawn, death.extraEnemyPos[i].position, Quaternion.identity);
                     spawn.GetComponent <EnemyMovement>().pathCount = testEnemy.pathCount;
                 }
             }
             testEnemy.ResetAnime();
             enemy.GetComponent <Animator>().SetTrigger("isDying");
             testEnemy.alive = false;
             enemies.Remove(enemy);
             Destroy(enemy, timeOfDeath);
             break;
         }
     }
 }
    // Start is called before the first frame update
    void Awake()
    {
        // Initialize components
        rb2d      = GetComponent <Rigidbody2D>();
        behaviour = GetComponent <EnemyDeath>();
        // Initialize up and down movement
        _ = StartCoroutine(nameof(SwitchVerticalMovement));
        // Play sound
        switch (enemyType)
        {
        case "small":
            audioSource = GameObject.Find("SmallEnemySoundSource").GetComponent <AudioSource>();
            if (EnemyControl.instance.smallEnemies == 0)
            {
                audioSource.clip = enemySounds[Random.Range(0, enemySounds.Length)];
                audioSource.Play();
            }
            EnemyControl.instance.smallEnemies++;
            break;

        case "big":
            audioSource = GameObject.Find("BigEnemySoundSource").GetComponent <AudioSource>();
            if (EnemyControl.instance.bigEnemies == 0)
            {
                audioSource.clip = enemySounds[Random.Range(0, enemySounds.Length)];
                audioSource.Play();
            }
            EnemyControl.instance.bigEnemies++;
            break;
        }
    }
Esempio n. 3
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        GameObject hitObject = collision.gameObject;
        EnemyDeath enemy     = hitObject.GetComponent <EnemyDeath>();

        if (hitObject == GameObject.Find("Player"))
        {
            PlayerCharacter p = hitObject.GetComponent <PlayerCharacter>();
            p.Hurt();
            Destroy(this.gameObject);
        }
        else if (enemy != null)
        {
            EnemyDeath e = hitObject.GetComponent <EnemyDeath>();
            e.Die();
            Destroy(this.gameObject);
        }
        else
        {
            var speed     = lastVelocity.magnitude; //We can reduce this if we want
            var direction = Vector3.Reflect(lastVelocity.normalized, collision.contacts[0].normal);

            rb.velocity = direction * speed;
        }
    }
Esempio n. 4
0
 //Instantiate all references
 void Awake()
 {
     Player        = GameObject.FindGameObjectWithTag("Player");
     explode       = GetComponent <EnemyDeath> ();
     currenthealth = starthealth;
     Target        = Player.transform;
 }
Esempio n. 5
0
 void Start()
 {
     players           = GameManager.m_Instance.m_Players;
     agent             = gameObject.GetComponent <NavMeshAgent>();
     m_Origin          = gameObject.transform.position;
     Script_enemydeath = GetComponent <EnemyDeath>();
 }
Esempio n. 6
0
        private void Awake()
        {
            _stateMachine = new StateMachine();

            var idle   = new EnemyIdle(this);
            var attack = new EnemyAttack(this);
            var move   = new EnemyMove(this, _rigidbody);
            var death  = new EnemyDeath(this, _collider);

            At(idle, move, hasTarget());
            At(move, idle, lostTarget());

            At(move, attack, reachedTarget());

            At(attack, idle, lostTarget());
            At(attack, move, targetOutOfRange());

            At(idle, death, isDead());
            At(move, death, isDead());
            At(attack, death, isDead());

            Func <bool> hasTarget() => () => Target != null;
            Func <bool> lostTarget() => () => Target == null;
            Func <bool> reachedTarget() => () => Vector2.Distance(transform.position, Target.transform.position) < attackRange - 0.5f;
            Func <bool> targetOutOfRange() => () => Target != null && Vector2.Distance(transform.position, Target.transform.position) > attackRange - 0.5f;
            Func <bool> isDead() => () => health <= 0;

            void At(IState from, IState to, Func <bool> condition) => _stateMachine.AddTransition(from, to, condition);

            _stateMachine.SetState(idle);
        }
Esempio n. 7
0
 void Start()
 {
     if (enemyAttack == null)
     {
         canAttack = false;
     }
     else
     {
         canAttack = true;
     }
     if (enemyMovement == null)
     {
         canMove = false;
     }
     else
     {
         canMove = true;
     }
     if (enemyIdle == null)
     {
         canIdle = false;
     }
     else
     {
         canIdle = true;
     }
     enemyDeath = GetComponent <EnemyDeath>();
 }
Esempio n. 8
0
 //Establish all needed references
 void Awake()
 {
     anim          = GetComponent <Animator> ();
     explode       = GetComponent <EnemyDeath> ();
     audio         = GetComponent <AudioSource> ();
     currenthealth = starthealth;
 }
Esempio n. 9
0
        //Modified, base from here: https://github.com/Ralzar81/SkillBooks/blob/cf024383284c12fbf4f27e6611ba2384c96508b9/SkillBooks/SkillBooks.cs.
        static void BestiaryLoot_OnEnemyDeath(object sender, EventArgs e)
        {
            if (!SettingSpawnItem)
            {
                return;
            }

            EnemyDeath enemyDeath = sender as EnemyDeath;

            if (enemyDeath != null)
            {
                DaggerfallEntityBehaviour entityBehaviour = enemyDeath.GetComponent <DaggerfallEntityBehaviour>();
                if (entityBehaviour != null)
                {
                    EnemyEntity enemyEntity = entityBehaviour.Entity as EnemyEntity;
                    if (enemyEntity != null)
                    {
                        if (enemyEntity.MobileEnemy.Affinity == MobileAffinity.Human || HumanoidCheck(enemyEntity.MobileEnemy.ID))
                        {
                            int luckRoll = UnityEngine.Random.Range(1, 20) + ((playerEntity.Stats.LiveLuck / 10) - 5);
                            if (luckRoll > 18)
                            {
                                DaggerfallUnityItem bestiaryItem = ItemBuilder.CreateItem(ItemGroups.UselessItems2, BestiaryItem.templateIndex);
                                entityBehaviour.CorpseLootContainer.Items.AddItem(bestiaryItem);
                            }
                        }
                    }
                }
            }
        }
    void OnTriggerEnter(Collider other)
    {
        string theirTag = other.tag;

        if (theirTag == Tags.BOUNDARY || theirTag == Tags.PLAYER || theirTag == Tags.ENEMY_SHIP || theirTag == Tags.ENEMY_BOLT || theirTag == Tags.FORMATION)
        {
            // Since player has higher priority, it will take responsibility for the collision
            return;
        }

        GameObject theirExplosion = null;
        int        myScore        = 0;

        if (theirTag == Tags.ASTEROID || theirTag == Tags.PLAYER_BOLT)
        {
            if (theirTag == Tags.ASTEROID)
            {
                EnemyDeath enemyDeath = other.gameObject.GetComponent <EnemyDeath> ();
                if (enemyDeath == null)
                {
                    throw new SpaceShooterException("No Enemy death added to enemy type " + other.gameObject);
                }
                theirExplosion = enemyDeath.myExplosion;
            }

            EnemyDeath myDeath = gameObject.GetComponent <EnemyDeath> ();
            if (myDeath == null)
            {
                throw new SpaceShooterException("No Enemy Death added to enemy type " + gameObject);
            }
            myExplosion = myDeath.myExplosion;

            if (theirTag == Tags.PLAYER_BOLT)
            {
                myScore = myDeath.myScore;
            }
        }



        if (theirExplosion != null)
        {
            Instantiate(theirExplosion, other.transform.position, other.transform.rotation);
        }

        if (myExplosion != null)
        {
            Instantiate(myExplosion, transform.position, transform.rotation);
        }

        if (myScore > 0)
        {
            gameController.AddScore(myScore);
            gameController.KilledEnemy();
        }

        Destroy(other.gameObject);
        Destroy(gameObject);
    }
Esempio n. 11
0
 // Start is called before the first frame update
 protected override void Awake()
 {
     base.Awake();
     m_enemyMover  = GetComponent <EnemyMover>();
     m_enemySensor = GetComponent <EnemySensor>();
     m_enemyAttack = GetComponent <EnemyAttack>();
     m_enemyDeath  = GetComponent <EnemyDeath>();
 }
 void Begin()
 {
     enemySeeker       = GetComponent <EnemySeeker>();
     enemyCombo        = GetComponent <EnemyCombo>();
     enemyRetreat      = GetComponent <EnemyRetreat>();
     enemyRecoverer    = GetComponent <EnemyRecoverer>();
     enemyDeath        = GetComponent <EnemyDeath>();
     enemyGravityCheck = GetComponent <EnemyGravityCheck>();
 }
Esempio n. 13
0
 public static void AddInvoker_Battle_EnemyDeathEnd(EnemyDeath deathScript)
 {
     invokers_Battle_EnemyDeathEnd.Add(deathScript);
     //if (listeners_SpeedUpFX != null)
     foreach (UnityAction <int> listener in listeners_Battle_EnemyDeathEnd)
     {
         deathScript.AddListener_Battle_EnemyDeathEnd(listener);
     }
 }
    private void Die()
    {
        EnemySpawnManager.enemyCount--;
        EnemyDeath?.Invoke();

        //When an enemy dies half the timescale for 30 seconds
        GameManager.Instance.SlowGameForEnemyDeath();

        Destroy(gameObject);
    }
Esempio n. 15
0
    // Start is called before the first frame update
    void Awake()
    {
        enemy = GetComponent <Enemy>().data;
        enemyPlayerInteraction = GetComponent <EnemyPlayerInteraction>();
        enemyDeath             = GetComponent <EnemyDeath>();
        //particleRadius = FindObjectOfType<EnemyRadius>().gameObject;


        enemy.currHealth = enemy.maxHealth;
    }
Esempio n. 16
0
    protected override void Awake()
    {
        base.Awake();

        m_board       = Object.FindObjectOfType <Board>().GetComponent <Board>();
        m_enemyMover  = GetComponent <EnemyMover>();
        m_enemySensor = GetComponent <EnemySensor>();
        m_enemyDeath  = GetComponent <EnemyDeath>();
        m_player      = Object.FindObjectOfType <PlayerManager>().GetComponent <PlayerManager>();
    }
Esempio n. 17
0
    void Update()
    {
        if (enemiesRemainingToSpawn > 0 && Time.time > nextSpawnTime)
        {
            enemiesRemainingToSpawn--;
            nextSpawnTime = Time.time + currentWave.timeBetweenSpawns;

            EnemyDeath spawnedEnemy = Instantiate(enemy, transform.position, Quaternion.identity) as EnemyDeath;
            //spawnedEnemy.OnDeath += OnEnemyDeath;
        }
    }
Esempio n. 18
0
 protected virtual void Awake()
 {
     body2d         = GetComponent <Rigidbody2D>();
     collisionState = GetComponent <CollisionState>();
     enemyDeath     = GetComponent <EnemyDeath>();
     enemyFly       = GetComponent <EnemyFly>();
     moveForward    = GetComponent <MoveForward>();
     enemyReady     = GetComponent <EnemyReady>();
     playerInRange  = false;
     player         = GameObject.Find("Player");
 }
Esempio n. 19
0
    // Use this for initialization
    void Start()
    {
        //クラス取得
        enemyDeath = GetComponent <EnemyDeath>();
        //オーディオソース取得
        audioSource = GetComponent <AudioSource>();
        //ターゲット検索
        targetObject = GameObject.FindGameObjectWithTag("MainCamera");

        //カウントダウンクラス取得
        countDownController = GameObject.Find("CountDownUI").GetComponent <CountDownController>();
    }
Esempio n. 20
0
    void Shoot()
    {
        //railgunShoot.Play();
        FindObjectOfType <AudioManager>().PlaySound("PlayerShoot");
        gunKickBackAnim.Play("GunKickBack", -1, 0f);
        bulletCharge.Play();
        gunCircle.Play();
        bulletFlash.Play();
        gunBurstAmmo.Play();
        // bulletTrail.Play();
        hasBullet = false;

        RaycastHit hit;

        if (Physics.Raycast(cam.transform.position, cam.transform.forward, out hit, range))
        {
            //VFX
            GameObject impactVFX = Instantiate(gunImpactEffect, hit.point, Quaternion.LookRotation(hit.normal));
            Destroy(impactVFX, 1);



            //Shooting Enemy
            EnemyDeath enemy = hit.transform.GetComponent <EnemyDeath>();
            if (enemy != null)
            {
                enemy.Die();
                hasBullet = true;
                FindObjectOfType <AudioManager>().PlaySound("Reload");

                CameraShaker.Instance.ShakeOnce(magnitude, roughness, fadeInTime, fadeOutTime);
            }


            //Reverse Gravity
            if (hit.collider.CompareTag("ReverseGravity"))
            {
                ReverseGravity();
                hasBullet = true;
            }


            TrailSpawn(hit.point);
        }


        else
        {
            TrailSpawn(trailMissEnd.transform.position); //Not hitting anything
        }
    }
Esempio n. 21
0
    // Start is called before the first frame update
    void Awake()
    {
        enemyHealth = transform.parent.GetComponent <EnemyHealth>();
        enemyDeath  = transform.parent.GetComponent <EnemyDeath>();
        enemy       = transform.parent.GetComponent <Enemy>().data;

        peiScript = enemy.playerEnemy;

        circleParticles    = transform.GetChild(0).GetComponentInChildren <ParticleSystem>();
        circleParticlesOne = transform.GetChild(1).GetComponentInChildren <ParticleSystem>();
        circleParticlesTwo = transform.GetChild(2).GetComponentInChildren <ParticleSystem>();
        hitParticles       = transform.GetChild(3).GetComponentInChildren <ParticleSystem>();
        verticalParticles  = transform.GetChild(4).GetComponentInChildren <ParticleSystem>();
    }
    // Start is called before the first frame update
    void Awake()
    {
        rb              = GetComponent <Rigidbody>();
        enemy           = GetComponent <Enemy>().data;
        enemyDeath      = GetComponent <EnemyDeath>();
        enemyController = GetComponent <EnemyController>();
        playerEnemy     = enemy.playerEnemy;

        player       = GameObject.FindObjectOfType <Player>();
        playerHealth = FindObjectOfType <PlayerHealth>();

        camRig = GameObject.Find("CameraRig").GetComponent <CameraRig>();

        SetNewLocation(0);
    }
Esempio n. 23
0
        public void RestoreSaveData(object dataIn)
        {
            if (!enemy)
            {
                return;
            }

            EnemyData_v1 data = (EnemyData_v1)dataIn;

            if (data.loadID != LoadID)
            {
                return;
            }

            DaggerfallEntityBehaviour entityBehaviour = enemy.GetComponent <DaggerfallEntityBehaviour>();
            EnemySenses senses = enemy.GetComponent <EnemySenses>();
            EnemyMotor  motor  = enemy.GetComponent <EnemyMotor>();
            EnemyEntity entity = entityBehaviour.Entity as EnemyEntity;

            // Restore enemy career or class if different
            if (entity.EntityType != data.entityType || entity.CareerIndex != data.careerIndex)
            {
                SetupDemoEnemy setupEnemy = enemy.GetComponent <SetupDemoEnemy>();
                setupEnemy.ApplyEnemySettings(data.entityType, data.careerIndex, data.isHostile);
                setupEnemy.AlignToGround();
            }

            // Restore enemy position
            enemy.transform.position    = data.currentPosition;
            enemy.transform.rotation    = data.currentRotation;
            entity.MaxHealth            = data.startingHealth;
            entity.CurrentHealth        = data.currentHealth;
            entity.CurrentFatigue       = data.currentFatigue;
            entity.CurrentMagicka       = data.currentMagicka;
            motor.IsHostile             = data.isHostile;
            senses.HasEncounteredPlayer = true;

            // Set monster as dead
            if (data.isDead)
            {
                EnemyDeath enemyDeath = enemy.GetComponent <EnemyDeath>();
                if (enemyDeath)
                {
                    enemyDeath.Die(false);
                }
            }
        }
Esempio n. 24
0
    private void OnTriggerEnter(Collider other)
    {
        EnemyDeath enemy = other.GetComponent<EnemyDeath>();
        if(enemy != null)
        {
            enemy.Die();
            CameraShaker.Instance.ShakeOnce(magnitude, roughness, fadeInTime, fadeOutTime);
            s.hasBullet = true;
            FindObjectOfType<AudioManager>().PlaySound("Reload");

        }
        if (other.CompareTag("ReverseGravity"))
        {
            s.ReverseGravity();
            s.hasBullet = true;
            FindObjectOfType<AudioManager>().PlaySound("Reload");
        }
    }
Esempio n. 25
0
 // do explosions and things here
 private void die()
 {
     isAlive = false;
     if (CompareTag("Enemy"))
     {
         EnemyDeath ed = GetComponent <EnemyDeath> ();
         if (ed != null)
         {
             ed.onEnemyDeath();
         }
     }
     playRandomSound(DeathSounds);
     if (deathEffect != null)
     {
         Instantiate(deathEffect, transform.position, Quaternion.identity);
     }
     Destroy(gameObject);
 }
Esempio n. 26
0
 // Use this for initialization
 void Start()
 {
     vzriv     = GameObject.Find("Vzrivplay").GetComponent <AudioSource>();
     dopDamage = 1;
     speed     = Random.Range(-3f, 3f);
     dam       = 1;
     fireRate  = 0.5f;
     ed        = gameObject.GetComponent <EnemyDeath>();
     InvokeRepeating("CheckRotate", 8f, 3f);
     gs = GameObject.Find("GameManager").GetComponent <GameStats>();
     sr = gameObject.GetComponent <SpriteRenderer>();
     NextPos();
     rotatingSpeed = Random.Range(-3f, 3f);
     player1       = GameObject.FindGameObjectWithTag("Player").GetComponent <Player>();
     gamemanager   = GameObject.Find("GameManager");
     menu          = gamemanager.GetComponent <Menu>();
     spawnmob      = gamemanager.GetComponent <SpawnMobs>();
 }
    void OnTriggerEnter(Collider other)
    {
        string theirTag = other.tag;

        if (theirTag == Tags.BOUNDARY || theirTag == Tags.FORMATION)
        {
            return;
        }

        GameObject theirExplosion = null;
        int        scoreValue     = 0;

        if (theirTag == Tags.ENEMY_SHIP || theirTag == Tags.ASTEROID)
        {
            EnemyDeath enemyDeath = other.gameObject.GetComponent <EnemyDeath> ();
            if (enemyDeath == null)
            {
                throw new SpaceShooterException("No enemy death script added for enemy:" + other.gameObject);
            }
            theirExplosion = enemyDeath.myExplosion;
            scoreValue     = enemyDeath.myScore;

            if (theirTag == Tags.ENEMY_SHIP)
            {
                gameController.KilledEnemy();
            }
        }
        else

        if (theirExplosion != null)
        {
            Instantiate(theirExplosion, other.transform.position, other.transform.rotation);
        }

        if (scoreValue > 0)
        {
            gameController.AddScore(scoreValue);
        }

        Destroy(other.gameObject);

        gameController.PlayerHit(myExplosion, transform);
    }
 // Start is called before the first frame update
 void Awake()
 {
     // Variable assignment
     currXSpeed = xSpeed;
     currYSpeed = ySpeed;
     // Get components
     rb2d        = GetComponent <Rigidbody2D>();
     behaviour   = GetComponent <EnemyDeath>();
     audioSource = GameObject.Find("MediumEnemySoundSource").GetComponent <AudioSource>();
     // Assign initial velocity
     rb2d.velocity = new Vector2(currXSpeed, currYSpeed);
     // Play sound
     if (EnemyControl.instance.mediumEnemies == 0)
     {
         audioSource.clip = enemySounds[Random.Range(0, enemySounds.Length)];
         audioSource.Play();
     }
     EnemyControl.instance.mediumEnemies++;
 }
Esempio n. 29
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        GameObject    hitObject = collision.gameObject;
        EnemyDeath    enemy     = hitObject.GetComponent <EnemyDeath>();
        ShieldPowerUp shield    = hitObject.GetComponent <ShieldPowerUp>();

        if (hitObject == GameObject.Find("Player"))
        {
            PlayerCharacter p = hitObject.GetComponent <PlayerCharacter>();
            p.Hurt();
            Destroy(this.gameObject);
        }
        else if (enemy != null)
        {
            EnemyDeath e = hitObject.GetComponent <EnemyDeath>();
            e.Die();
            Destroy(this.gameObject);
            FindObjectOfType <PlayerCharacter>().StreakIncrease();
        }
        else if (shield != null && firstWall == false)
        {
            Destroy(this.gameObject);
        }
        else if (shield != null && firstWall == true)
        {
        }
        else
        {
            var speed     = lastVelocity.magnitude; //We can reduce this if we want
            var direction = Vector3.Reflect(lastVelocity.normalized, collision.contacts[0].normal);

            rb.velocity = (direction * speed) * 0.95f;

            if (firstWall == true)
            {
                FindObjectOfType <PlayerCharacter>().StreakReset();
                firstWall = false;
            }
        }
    }
Esempio n. 30
0
        public static void EnemyDeath_OnEnemyDeath(object sender, EventArgs e)
        {
            EnemyDeath enemyDeath = sender as EnemyDeath;

            if (enemyDeath != null)
            {
                DaggerfallEntityBehaviour entityBehaviour = enemyDeath.GetComponent <DaggerfallEntityBehaviour>();
                if (entityBehaviour != null)
                {
                    EnemyEntity enemyEntity = entityBehaviour.Entity as EnemyEntity;
                    if (enemyEntity != null)
                    {
                        if (entityBehaviour.GetComponent <EnemySenses>().Target == GameManager.Instance.PlayerEntityBehaviour)
                        {
                            string monsterName = AllTextClass.MonsterCareerIndexToString(enemyEntity.CareerIndex);
                            if (killCounts.ContainsKey(monsterName))
                            {
                                killCounts[monsterName] += 1;
                                for (int i = 0; i < AllText.Pages.Count; i++)
                                {
                                    AllText.Pages[i].PageSummary = new Summary(AllText.Pages[i].PageSummary.Name);
                                }
                            }
                            else
                            {
                                if (SettingEntries == 1 && monsterName != "false")
                                {
                                    DaggerfallUI.AddHUDText(String.Format("{0} has been added to the Bestiary.", new List <string>(mod.GetAsset <TextAsset>(monsterName).text.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries))[2]));
                                }

                                killCounts.Add(monsterName, 1);
                                InitializeUI();
                            }
                        }
                    }
                }
            }
        }
Esempio n. 31
0
        private void AddEnemy()
        {
            Enemy enemy = new Enemy();

            Animation enemyAnimation = new Animation();
            enemyAnimation.Initialize(_enemyTexture, Vector2.Zero, 47, 61, 8, 30, Color.White, 1f, true);

            Vector2 position = new Vector2(_screenWidth + _enemyTexture.Width / 2,
                _random.Next(10, _screenHeight - 50));

            Death death = new EnemyDeath();
            death.Initialize(_explosionFactory);

            if (_hitboxTexture != null)
            {
                enemy.Initialize(enemyAnimation, death, position, _hitboxTexture); 
            }
            else
            {
                enemy.Initialize(enemyAnimation, death, position);
            }

            Enemies.Add(enemy);
        }
Esempio n. 32
0
 void Awake()
 {
     enemyAI = GetComponent<EnemyAI>();
     enemyDeath = GetComponent<EnemyDeath>();
 }