コード例 #1
0
ファイル: EnemyStates.cs プロジェクト: Niggita/Ravenloft
 protected virtual void InitializeDamageState(Enemy enemy)
 {
     if (enemyHit == null)
     {
         enemyHit = new EnemyHit(enemy);
     }
 }
コード例 #2
0
    void Shooting()
    {
        gunShoot.Play();
        animator.SetTrigger("Shoot");
        shootParticle.Play();
        RaycastHit hit;
        Vector3    direction = shootPoint2.transform.position - shootPoint1.transform.position;

        if (Physics.Raycast(shootPoint1.transform.position, direction, out hit, Mathf.Infinity))
        {
            if (hit.transform.gameObject.CompareTag("Player"))
            {
                PlayerHit playerHit = hit.transform.gameObject.GetComponent <PlayerHit>();
                playerHit.RestartLevel();
            }
            else
            {
                if (hit.transform.gameObject.CompareTag("Enemy"))
                {
                    EnemyHit enemyHit = hit.transform.gameObject.GetComponent <EnemyHit>();
                    enemyHit.Dead();
                }
            }
        }
    }
コード例 #3
0
ファイル: PlayerMove.cs プロジェクト: yurippeeee/onigokko
 void Start()
 {
     character_controller = GetComponent <CharacterController>();
     animator             = GetComponent <Animator>();
     //右足のコライダーを取得
     right_foot_collider         = transform.Find("Character1_Reference").transform.Find("Character1_Hips").transform.Find("Character1_RightUpLeg").transform.Find("Character1_RightLeg").transform.Find("Character1_RightFoot").transform.Find("Character1_RightToeBase").GetComponent <SphereCollider>();
     right_foot_collider.enabled = false;
     //右足の衝突処理をするスクリプト
     enemy_hit = transform.Find("Character1_Reference").transform.Find("Character1_Hips").transform.Find("Character1_RightUpLeg").transform.Find("Character1_RightLeg").transform.Find("Character1_RightFoot").transform.Find("Character1_RightToeBase").GetComponent <EnemyHit>();
 }
コード例 #4
0
ファイル: Entity.cs プロジェクト: cloera/ZombieGame
    public virtual void OnHit(EnemyHit hit)
    {
        health         -= hit.damage;
        healthBar.value = health;

        if (health <= 0)
        {
            Dead();
        }
    }
コード例 #5
0
 public void TakeDamage(GameObject HitData, EnemyHit PartHit)
 {
     attackData = HitData.GetComponent <BasicAttackData>();
     if (PartHit.BreakablePart == true)
     {
         PartHit.PartHealth = PartHit.PartHealth - (attackData.DamageValue * PartHit.PartDamageMulti);
         Debug.Log("Part Health: " + PartHit.PartHealth);
     }
     EnemyHealth = EnemyHealth - (attackData.DamageValue * PartHit.PartDamageMulti);
     Debug.Log("Enemy Health: " + EnemyHealth);
 }
コード例 #6
0
 protected void Awake()
 {
     rb           = GetComponent <Rigidbody2D>();
     hitboxes     = GetComponentsInChildren <Collider2D>();
     dormant      = new EnemyDormant(this.gameObject, this);
     idle         = new EnemyIdle(gameObject, this);
     approach     = new EnemyApproach(gameObject, this);
     attack       = new EnemyAttack(gameObject, this);
     hitState     = new EnemyHit(gameObject, this);
     currentState = idle;
 }
コード例 #7
0
    public void Setup(Func <Vector2> getPlayerFunc, PlayerHealth playerHealth, GameManager gameManager)
    {
        enemyMovement = instance.GetComponent <EnemyMovementScript>();
        enemyMovement.Setup(getPlayerFunc);
        enemyMovement.enabled = true;

        enemyHit = instance.GetComponent <EnemyHit>();
        enemyHit.playerHealth = playerHealth;

        enemyHealth = instance.GetComponent <EnemyHealth>();
        enemyHealth.Setup(gameManager);
    }
コード例 #8
0
 public void ResetLevel()
 {
     foreach (GameObject enemy in enemies)
     {
         EnemyHit enemyHit = enemy.GetComponent <EnemyHit>();
         enemyHit.aiming.enabled   = false;
         enemyHit.shoot.enabled    = false;
         enemyHit.rotating.enabled = false;
         enemyHit.line.SetActive(false);
         enemyHit.transform.position = poolingPlace.transform.position;
     }
     currentLevel--;
     numberOfEnemiesOnLevel = 0;
 }
コード例 #9
0
    /// <summary>
    /// 添加事件的时候,需要在我们的脚本中添加一个与事件名字相同的方法,否则会报错
    /// </summary>
    void Attack()
    {
        //本地从标和局部从标
        List <GameObject> enemyList = GetAttackRangeEnemy();

        if (enemyList.Count > 0)      //如果可攻击的敌人数量大于零
        //遍历敌人集合
        {
            for (int i = 0; i < enemyList.Count; i++)
            {
                //得到第i个敌人身上的伤害脚本
                EnemyHit hit = enemyList[i].GetComponent <EnemyHit>();
                hit.Hit(50);
            }
        }
    }
コード例 #10
0
    public void Spawn()
    {
        var.enemies[var.NumberOfEnemies()].transform.position = transform.position;
        var.enemies[var.NumberOfEnemies()].transform.rotation = transform.rotation;

        EnemyHit enemyHit = var.enemies[var.NumberOfEnemies()].GetComponent <EnemyHit>();

        enemyHit.aiming.enabled = true;

        enemyHit.rotating.enabled = true;

        enemyHit.shoot.enabled = true;

        enemyHit.line.SetActive(true);

        var.SetNumberOfEnemiesOnLevel(var.NumberOfEnemies() + 1);
    }
コード例 #11
0
 public void RestartGame()
 {
     restartExitMenu.SetActive(false);
     endMenu.SetActive(false);
     menuButton.SetActive(true);
     playerShootScript.enabled = true;
     foreach (GameObject enemy in enemies)
     {
         EnemyHit enemyHit = enemy.GetComponent <EnemyHit>();
         enemyHit.aiming.enabled   = false;
         enemyHit.shoot.enabled    = false;
         enemyHit.rotating.enabled = false;
         enemyHit.line.SetActive(false);
         enemyHit.transform.position = poolingPlace.transform.position;
     }
     currentLevel           = 0;
     numberOfEnemiesOnLevel = 0;
 }
コード例 #12
0
 //Decreases the health by a given amount
 public void take_damage(float amount)
 {
     if (tag.Equals("Player"))
     {
         AM.Play("PlayerHit");
         StartCoroutine(PH.ColorChange(PH.changeTime));
     }
     if (tag.Equals("Broad") || tag.Equals("SimpleEnemy"))
     {
         if (health > 0f)
         {
             EnemyHit EH = this.GetComponent <EnemyHit>();
             StartCoroutine(EH.ColorChange(EH.changeTime));
             AM.Play("BroadHit");
         }
     }
     if (amount < 0)
     {
         Debug.LogWarning("Cannot cause negative damage!");
     }
     health = Mathf.Max(health - amount, 0);
 }
コード例 #13
0
        // Update is called once per frame
        void Update()
        {
            Ray _ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            RaycastHit[] _hitInfos = Physics.RaycastAll(_ray, 100f);

            if (_hitInfos == null)
            {
                Debug.Log("destination is not defined");
                return;
            }

            //Action based on Priority
            foreach (RaycastHit hit in _hitInfos)
            {
                if (hit.collider.gameObject.tag == "Enemy")
                {
                    if (Input.GetMouseButtonDown(0))
                    {
                        print("enemy hit");
                        EnemyHit.Invoke(hit);
                        break;
                    }
                    else
                    {
                        //TODO add outline highlighter in here
                    }
                }
                else if (hit.collider.gameObject.tag == "Terrain")
                {
                    if (Input.GetMouseButtonDown(0))
                    {
                        print("terrain hit");
                        TerrainHit.Invoke(hit);
                    }
                }
            }
        }
コード例 #14
0
 public void OnEnemyHit()
 {
     EnemyHit?.Invoke(this);
 }
コード例 #15
0
ファイル: Test.cs プロジェクト: ElowanGames/2018-ld42
 private void Start()
 {
     enemy = FindObjectOfType <EnemyHit>();
     anim  = GetComponentInParent <Animator>();
 }
コード例 #16
0
 public void AddPartToList(EnemyHit Part)
 {
     Parts.Add(Part);
 }
コード例 #17
0
 void Start()
 {
     LoadData();
     enemyHit = gameObject.GetComponent <EnemyHit>();
 }
コード例 #18
0
ファイル: Moose.cs プロジェクト: cloera/ZombieGame
 public override void OnHit(EnemyHit hit)
 {
     base.OnHit(hit);
     CanadianFury();
 }
コード例 #19
0
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            List <Bullet> bulletRemove = new List <Bullet>();

            foreach (Bullet bullets in Bullets.Children)
            {
                bullets.Update(gameTime);

                if (bullets.offScreen)
                {
                    bulletRemove.Add(bullets);
                }
            }
            List <Enemy> enemyRemove = new List <Enemy>();

            foreach (Enemy Enemies in Enemies.Children)
            {
                Enemies.Update(gameTime);

                foreach (Bullet BulletHit in Bullets.Children)
                {
                    if (BulletHit.CollidesWith(Enemies))
                    {
                        score.getScore = score.getScore + _scoreUp;
                        bulletRemove.Add(BulletHit);
                        enemyRemove.Add(Enemies);
                    }
                }
            }
            foreach (Enemy enemy in enemyRemove)
            {
                Enemies.Remove(enemy);
            }
            foreach (Bullet bullets in bulletRemove)
            {
                Bullets.Remove(bullets);
            }

            for (int i = Enemies.Children.Count; i < _amountOfEnemies; i++)
            {
                Enemies.Add(new Enemy());
            }

            if (_hit == true)
            {
                _frameCounter++;
            }
            foreach (Enemy EnemyHit in Enemies.Children)
            {
                if (EnemyHit.CollidesWith(thePlayer))
                {
                    if (_hit == false)
                    {
                        foreach (Health health in Health.Children)
                        {
                            if (_healthRemove == false)
                            {
                                KillList.Add(health);
                                _healthRemove = true;
                            }
                        }
                        _healthRemove = false;
                        _hit          = true;

                        thePlayer.HEALTH = thePlayer.HEALTH - _hpDown;
                    }
                }
            }
            if (_frameCounter >= 60)
            {
                _hit          = false;
                _frameCounter = 0;
            }
            foreach (Health health in Health.Children)
            {
            }

            foreach (var aObject in KillList.Children)
            {
                Health.Remove(aObject);
            }

            if (thePlayer.HEALTH <= 0)
            {
                GameEnvironment.GameStateManager.SwitchTo("GameOver");
                thePlayer.Reset();
                Enemies.Reset();
                Health.Reset();
                score.getScore   = 0;
                thePlayer.HEALTH = 3;
                for (int i = 0; i < _healtPoints; i++)
                {
                    Health.Add(new Health(new Vector2(150 - (i * _space), 10)));
                }
            }
        }