예제 #1
0
        void Update()
        {
            float distanceToPlayer = Vector3.Distance(player.transform.position, transform.position);

            if (distanceToPlayer <= attackRadius && !isAttacking)
            {
                isAttacking = true;
                InvokeRepeating("FireProjectile", 0f, secondsBetweenShots); // TODO switch to coroutines
            }

            if (distanceToPlayer > attackRadius)
            {
                isAttacking = false;
                CancelInvoke();
            }

            if (distanceToPlayer <= chaseRadius)
            {
                aiCharacterControl.SetTarget(player.transform);
            }
            else
            {
                aiCharacterControl.SetTarget(transform);
            }
        }
예제 #2
0
파일: Enemy.cs 프로젝트: Arumenn/Darkness
        // Update is called once per frame
        void Update()
        {
            if (player.healthAsPercentage <= Mathf.Epsilon)
            {
                //player is already dead
                StopAllCoroutines();
                Destroy(this); //to stop enemy behaviour
                return;
            }

            float distanceToPlayer = Vector3.Distance(player.transform.position, transform.position);

            if ((distanceToPlayer <= attackRadius) && (!isAttacking))
            {
                isAttacking = true;
                float randomizedDelay = UnityEngine.Random.Range(firingPeriodInSeconds - firingPeriodVariation, firingPeriodInSeconds + firingPeriodVariation);
                InvokeRepeating("FireProjectile", 0f, randomizedDelay); //TODO switch to Coroutines
            }
            if (distanceToPlayer > attackRadius)
            {
                CancelInvoke("FireProjectile");
                isAttacking = false;
            }

            if (distanceToPlayer <= chaseRadius)
            {
                //start chasing
                aICharacterControl.SetTarget(player.transform);
            }
            else
            {
                aICharacterControl.SetTarget(transform);
            }
        }
예제 #3
0
 void OnMouseOverEnemy(Enemy enemy)
 {
     if (Input.GetMouseButton(0) || Input.GetMouseButtonDown(1))
     {
         aiCharacterControl.SetTarget(enemy.transform);
     }
 }
예제 #4
0
        void Update()
        {
            if (player.healthAsPercentage <= Mathf.Epsilon)
            {
                StopAllCoroutines();
                Destroy(this); // To stop enemy behaviour
            }

            float distanceToPlayer = Vector3.Distance(player.transform.position, transform.position);

            if (distanceToPlayer <= attackRadius && !isAttacking)
            {
                isAttacking = true;
                float randomisedDelay = Random.Range(firingPeriodInS - firingPeriodVariation, firingPeriodInS + firingPeriodVariation);
                InvokeRepeating("FireProjectile", 0f, randomisedDelay);
            }

            if (distanceToPlayer > attackRadius)
            {
                isAttacking = false;
                CancelInvoke();
            }

            if (distanceToPlayer <= chaseRadius)
            {
                aiCharacterControl.SetTarget(player.transform);
            }
            else
            {
                aiCharacterControl.SetTarget(transform);
            }
        }
예제 #5
0
        void Update()
        {
            float distance = Vector3.Distance(player.transform.position, transform.position);

            if (distance <= attackRadius && !isAttacking)
            {
                isAttacking = true;
                print(gameObject.name + " attackingPlayer");

                InvokeRepeating("FireProjectile", 0f, secondsBetweenShots);
                //TODO make a proper coroutine
            }

            if (distance > attackRadius)
            {
                CancelInvoke();
                isAttacking = false;
            }
            else
            {
                aICharacterControl.SetTarget(transform);
            }


            if (distance < chaseRadius)
            {                                 //shift alt a comment all
                aICharacterControl.SetTarget(player.transform);
            }
            else
            {
                aICharacterControl.SetTarget(transform);
            }
        }
예제 #6
0
파일: Enemy.cs 프로젝트: trentonwuerker/RPG
        void Update()
        {
            if (player.healthAsPercentage <= Mathf.Epsilon)
            {
                StopAllCoroutines();
                Destroy(this);
            }
            float distanceToPlayer = Vector3.Distance(player.transform.position, transform.position);

            if (distanceToPlayer <= attackRadius && !isAttacking)
            {
                isAttacking = true;
                InvokeRepeating("FireProjectile", 0f, secondsBetweenShots);
            }
            if (distanceToPlayer > attackRadius)
            {
                isAttacking = false;
                CancelInvoke();
            }

            if (distanceToPlayer <= chaseRadius)
            {
                aiCharacterControl.SetTarget(player.transform);
            }
            else
            {
                aiCharacterControl.SetTarget(transform);
            }
        }
예제 #7
0
 void OnMouseOverPotentiallyWalkable(Vector3 destination)
 {
     if (Input.GetMouseButton(0))
     {
         walkTarget.transform.position = destination;
         aiCharacterControl.SetTarget(walkTarget.transform);
     }
 }
예제 #8
0
        void Update()
        {
            distanceToPlayer = Vector3.Distance(player.transform.position, transform.position);
            currentTime      = Time.time;

            UpdateImmunityGracePeriod();

            if (distanceToPlayer <= aggroRange)
            {
                MakeMoveAttackDecision();
            }
            else
            {
                // do nothing
                aICharacterControl.SetTarget(transform);
            }
        }
예제 #9
0
        void ProcessMouseClick(RaycastHit raycastHit, int layerHit)
        {
            switch (layerHit)
            {
            case enemyLayerNumber:
                GameObject enemy = raycastHit.collider.gameObject;
                aiCharacterControl.SetTarget(enemy.transform);
                break;

            case walkableLayerNumber:
                walkTarget.transform.position = raycastHit.point;
                aiCharacterControl.SetTarget(walkTarget.transform);
                break;

            default:
                Debug.LogWarning("Don't know how to handle click for player movement");
                return;
            }
        }
예제 #10
0
        void ProcessMouseClick(RaycastHit raycastHit, int layerHit)
        {
            switch (layerHit)
            {
            case 8:     //walkable
                walkTarget.transform.position = raycastHit.point;
                aiCharacterControl.SetTarget(walkTarget.transform);
                break;

            case 9:     //enemy
                GameObject enemy = raycastHit.collider.gameObject;
                aiCharacterControl.SetTarget(enemy.transform);
                break;

            default:      //everything else
                Debug.LogWarning("Invalid Movement");
                return;
            }
        }
예제 #11
0
        void ProcessMouseClick(RaycastHit raycastHit, int layerHit)
        {
            switch (layerHit)
            {
            case enemyLayerNumber:
                //navigate to the enemy
                GameObject enemy = raycastHit.collider.gameObject;
                aiCharacterControl.SetTarget(enemy.transform);
                break;

            case walkableLayerNumber:
                //navigate to point on the ground
                walkTarget.transform.position = raycastHit.point;
                aiCharacterControl.SetTarget(walkTarget.transform);
                break;

            default:
                Debug.Log("Dont know how to handle mouse clikc or player momevement");
                break;
            }
        }
예제 #12
0
        private void ProcessMouseClick(RaycastHit raycastHit, int layerHit)
        {
            switch (layerHit)
            {
            case enemyLayerNumber:
                // navigate to enemy
                GameObject enemy = raycastHit.collider.gameObject;
                aiCharacterControl.SetTarget(enemy.transform);
                break;

            case walkableLayerNumber:
                // navigate to point on gorund
                walkTarget.transform.position = raycastHit.point;
                aiCharacterControl.SetTarget(walkTarget.transform);
                break;

            default:
                Debug.LogWarning("Cant handle layer in ProcessMouseClick");
                break;
            }
        }
예제 #13
0
        // try mouse button (1) for pathifnding to enemies while still using ThirdPersonController script

        void MouseOverEnemy(Enemy enemy)
        {
            if (Input.GetMouseButtonDown(1))
            {
                AIControl.SetTarget(enemy.transform);
                float distance = (transform.position - enemy.transform.position).magnitude;
                if (distance <= NavMesh.stoppingDistance)
                {
                    AIControl.ResetTarget();
                }
            }
        }
예제 #14
0
 void WalkTo(Vector3 destinationPosition)
 {
     //Vector3 pos = new Vector3(destinationPosition.x, 0f, destinationPosition.z);
     walkTarget.transform.position = destinationPosition;
     aICharacterControl.SetTarget(walkTarget.transform);
 }