Beispiel #1
0
 public void CheckSide(EnemyInfoHolder _enemyInfoHolder)
 {
     if (transform.position.x - _enemyInfoHolder.playerGameObject.transform.position.x < 0)
     {
         transform.rotation = new Quaternion(0, 180, 0, 0);
     }
     else
     {
         transform.rotation = new Quaternion(0, 0, 0, 0);
     }
 }
Beispiel #2
0
    // Update is called once per frame
    void Update()
    {
        if (!isRegistered)
        {
            print("registering ennemy");
            GameManager.registerEnemy(this.gameObject);
            isRegistered = true;
        }
        if (!gotPlayerPoint)
        {
            _enemyInfoHolder = GameManager.getInfo4Enemy(this.gameObject.transform);

            /* moved inside the if (NullReferenceException: Object reference not set to an instance of an object
             *                              EnemyAI.Update () (at Assets/Scripts/EnemyAI.cs:37)) -alon*/
            if (_enemyInfoHolder.point != null)
            {
                range = Vector3.Distance(this.transform.position, _enemyInfoHolder.point.dockPoint.position); //range between enemy and player
            }
        }

        if (_enemyInfoHolder != null && GameManager.isFreePoints())
        {
            if (range < 0.1) // checks when enemy is near the player attack point and then occupies it
            {
                _enemyInfoHolder.point.occupied = 1;
                gotPlayerPoint = true;
                // alon
                Debug.Log("inragne");
                EnemyAttack.playerInRange = true;
            }
            transform.position = Vector3.MoveTowards(this.transform.position, _enemyInfoHolder.point.dockPoint.position, moveSpeed * Time.deltaTime);
        }
        float rangeFromPlayer = Vector3.Distance(this.transform.position, _enemyInfoHolder.playerGameObject.transform.position);

        print(rangeFromPlayer);
        if (rangeFromPlayer > 0.30f)//releases the attack point if the enemy is not near it
        {
            if (_enemyInfoHolder.point != null)
            {
                _enemyInfoHolder.point.occupied = 0;                                //REFACTOR THIS
            }
            gotPlayerPoint = false;
            if (EnemyAttack != null)
            {
                EnemyAttack.playerInRange = false;
            }
            print("releasing point");
        }
        CheckSide(_enemyInfoHolder); // this changes rotation according to player location
    }
Beispiel #3
0
    // Update is called once per frame
    private void Update()
    {
        if (!isRegistered)
        {
//            print("registering ennemy");
            GameManager.registerEnemy(gameObject);
            isRegistered = true;
        }
        if (!gotPlayerPoint && GameManager.isFreePoints())
        {
            _enemyInfoHolder = GameManager.getInfo4Enemy(gameObject.transform);
        }


        if (!stop)
        {
            if (GameManager.isFreePoints())
            {
                range = Vector3.Distance(transform.position, _enemyInfoHolder.point.dockPoint.position);

                if (range <= 0.2f) // checks when enemy is near the player dock point and then occupies it
                {
                    if (!gotPlayerPoint)
                    {
                        GameManager.OccupyPoint(_enemyInfoHolder.point);
                        gotPlayerPoint = true;
                        pointHolding   = _enemyInfoHolder.point.name;
                    }
                    if (STATE != ANIM.ATTACKING)
                    {
//                    print(gameObject.name);


                        STATE = ANIM.ATTACKING;
                    }
                    timer += Time.deltaTime;
                    if (gotPlayerPoint && timer >= timeBetweenAttacks)
                    {
                        AttackPlayer();
                    }
                    else
                    {
//                 animator.Play("stand");
                    }
                }
                else if (range > 0.3f)
                {
                    timer = 0f;
                    if (STATE != ANIM.WALKING)
                    {
                        if (gotPlayerPoint)
                        {
                            GameManager.ReleasePoint(_enemyInfoHolder.point);
                        }
                        gotPlayerPoint = false;
                        isMoving       = true;
                        STATE          = ANIM.WALKING;
                        animator.Play("Walking");
                    }
                }

                if (STATE == ANIM.WALKING)
                {
                    if (dodging)
                    {
                        dodge();
                    }
                    else if (MOVEMENT == BLOCKED.NULL)
                    {
                        float oldY = transform.position.y;

                        transform.position = Vector3.MoveTowards(transform.position,
                                                                 _enemyInfoHolder.point.dockPoint.position, moveSpeed * Time.deltaTime);
                        isMoving = true;

                        if (transform.position.y >= 1.76f)
                        {
                            transform.position = new Vector3(transform.position.x, oldY, transform.position.z);
                            MOVEMENT           = BLOCKED.UP;
                            TURN     = DODGE.DOWN;
                            dodging  = true;
                            isMoving = true;
                        }
                        else if (transform.position.y <= 0.18f)
                        {
                            transform.position = new Vector3(transform.position.x, oldY, transform.position.z);
                            MOVEMENT           = BLOCKED.DOWN;
                            TURN     = DODGE.UP;
                            dodging  = true;
                            isMoving = true;
                        }
                    }
                    else
                    {
                        rayHit();
                    }
                }
            }
        }

        CheckSide(_enemyInfoHolder); // this changes rotation according to player location
    }
Beispiel #4
0
 void Awake()
 {
     gameManagerInstance = this;
     enemyInfoList       = new EnemyInfoHolder();
 }