コード例 #1
0
ファイル: EnemyBehavior.cs プロジェクト: maxdraz/overcoaled
    private void Update()
    {
        if (!arrived)
        {
            transform.position = Vector3.MoveTowards(transform.position, destination, moveToPointSpeed * Time.deltaTime);

            if (Vector3.Distance(transform.position, destination) < 0.001f)
            {
                arrived = true;
            }
        }
        else if (arrived)
        {
            shootTarget = null;

            foreach (WallClass wall in wallManager.Walls)
            {
                if (wall.wall != null)
                {
                    if (wall.position == targetAreaToIndex(target))
                    {
                        if (shootTarget != null)
                        {
                            if (wall.wall != null)
                            {
                                if (Vector3.Distance(wall.wall.transform.position, transform.position)
                                    < Vector3.Distance(shootTarget.position, transform.position))
                                {
                                    if (wall.wall != null)
                                    {
                                        shootTarget = wall.wall.transform;
                                    }
                                }
                            }
                        }
                        else
                        {
                            if (wall.wall != null)
                            {
                                shootTarget = wall.wall.transform;
                            }
                        }
                    }
                }
            }


            //if (target == carriage.back)
            //{
            //    if (passengerManager.passengers.Count > 0)
            //    {
            //        int passengerNumber = Random.Range(0, passengerManager.passengers.Count);
            //        if (passengerManager.passengers[passengerNumber])
            //        {
            //            shootTarget = passengerManager.passengers[passengerNumber].transform;
            //        }
            //    }
            //}

            bool cargoPriority = false;
            foreach (GameObject passenger in passengerManager.passengers)
            {
                if (passenger)
                {
                    if (passenger.transform.position.x < targetDistanceMax(target) &&
                        passenger.transform.position.x > targetDistanceMin(target))
                    {
                        if (shootTarget != null)
                        {
                            if (cargoPriority)
                            {
                                if (Vector3.Distance(passenger.transform.position, transform.position)
                                    < Vector3.Distance(shootTarget.position, transform.position))
                                {
                                    shootTarget   = passenger.transform;
                                    cargoPriority = true;
                                }
                            }
                            else
                            {
                                shootTarget   = passenger.transform;
                                cargoPriority = true;
                            }
                        }
                        else
                        {
                            shootTarget   = passenger.transform;
                            cargoPriority = true;
                        }
                    }
                }
            }



            bool playerPriority = false;
            foreach (Player player in players)
            {
                if (player.playerObject)
                {
                    if (player.playerObject.transform.position.x < targetDistanceMax(target) &&
                        player.playerObject.transform.position.x > targetDistanceMin(target))
                    {
                        if (shootTarget != null)
                        {
                            if (playerPriority)
                            {
                                if (Vector3.Distance(player.playerObject.transform.position, transform.position)
                                    < Vector3.Distance(shootTarget.position, transform.position))
                                {
                                    shootTarget    = player.playerObject.transform;
                                    playerPriority = true;
                                }
                            }
                            else
                            {
                                shootTarget    = player.playerObject.transform;
                                playerPriority = true;
                            }
                        }
                        else
                        {
                            shootTarget    = player.playerObject.transform;
                            playerPriority = true;
                        }
                    }
                }
            }

            if (shootTarget != null)
            {
                gun.AimAndShoot(shootTarget);
            }
        }

        throwDynamiteTimer -= Time.deltaTime;
        if (throwDynamiteTimer <= 0 && !dynamiteThrown)
        {
            spawnDynamite.AddDynamite();
            dynamiteThrown = true;
        }
    }