示例#1
0
    // Update is called once per frame
    void Update()
    {
        Ground = onGround;
        if (onGround == false)
        {
            state        = StateEnemy.down;
            rb.velocity -= Vector2.up * 2;
            return;
        }
        float distance = transform.position.x - target.transform.position.x;

        Debug.Log(distance);
        if (distance > 0)
        {
            transform.localScale = new Vector3(Mathf.Abs(transform.localScale.x), transform.localScale.y, transform.localScale.z);
            checkleft();
        }
        else
        {
            transform.localScale = new Vector3(-Mathf.Abs(transform.localScale.x), transform.localScale.y, transform.localScale.z);
            checkright();
        }
        if (onGround == false && state != StateEnemy.jump)
        {
            rb.velocity -= Vector2.up * 2;
        }



        switchstate();
    }
示例#2
0
    void Start()
    {
        ///Set Agent
        agent       = GetComponent <NavMeshAgent>();
        agent.speed = speed;
        maxLife     = life;

        ////Set Patrol
        currentState = StateEnemy.PATROL;
        UpdatePatrolPoint();

        ////Set Player
        GameObject auxPlayer = GameObject.FindGameObjectWithTag("Player");

        if (auxPlayer != null)
        {
            playerTransform = auxPlayer.transform;
            playerRB        = auxPlayer.GetComponent <Rigidbody>();
        }

        ////NAVMESH AGENT KNOCKBACK
        nma = GetComponentInParent <NavMeshAgent>();
        rb  = GetComponent <Rigidbody>();

        countDownToAttack = timeToAttack;
    }
示例#3
0
    void checkright()
    {
        Vector2      mytransform = transform.position + new Vector3(1, 0, 0);
        RaycastHit2D ray         = Physics2D.Raycast(mytransform, Vector2.right);

        Debug.DrawRay(transform.position, transform.TransformDirection(Vector2.right), Color.red);
        if (ray.collider != null && ray.collider.transform.root.tag == "Player")
        {
            isright = true;
            float distance = Vector3.Distance(transform.position, target.transform.position);
            print(distance);

            if (Mathf.Abs(distance) <= 2)
            {
                changestate();
            }
            if (Mathf.Abs(distance) > 2 && Mathf.Abs(distance) <= 4)
            {
                WalkThink();
            }
            if (Mathf.Abs(distance) > 4 && Mathf.Abs(distance) <= 6)
            {
                Think();
            }
            if (Mathf.Abs(distance) > 6)
            {
                state = StateEnemy.walk;
            }
        }
        else
        {
            isright = false;
        }
    }
示例#4
0
    protected void updateStateAndIfResetPath()
    {
        if (lastStateEnemy != stateEnemy)
        {
            agent.ResetPath();
            lastStateEnemy = stateEnemy;
            switch (stateEnemy)
            {
            case StateEnemy.STARTING:
            case StateEnemy.ATTACKING:
                changeMaterial(materialOriginal);
                agent.speed = speedAttackingStarting;
                break;

            case StateEnemy.ESCAPE:
                changeMaterial(materialEscape);
                agent.speed = speedEscaping;
                break;

            case StateEnemy.DEADING:
                changeMaterial(materialDead);
                agent.speed = speedDeading;
                break;

            default:
                agent.speed = speedAttackingStarting;
                break;
            }
        }
    }
示例#5
0
 private void Start()
 {
     state         = StateEnemy.lookingOut;
     m_animator    = GetComponent <Animator>();
     player        = FindObjectOfType <Player>().transform;
     startPosition = this.transform.position;
 }
示例#6
0
    IEnumerator respownCoroutine()
    {
        yield return(new WaitForSeconds(0.25f));

        agent.enabled                 = true;
        agent.nextPosition            = startingPosition;
        gameObject.transform.position = startingPosition;
        stateEnemy = StateEnemy.STARTING;
    }
示例#7
0
    void changestate()
    {
        int a = cheackplayerstate();

        switch (a)
        {
        case 0:

            int kickstate = Random.Range(0, 3);
            if (kickstate == 0)
            {
                state = StateEnemy.Punch;
            }
            else if (kickstate == 1)
            {
                state = StateEnemy.kick;
            }
            else
            {
                state = StateEnemy.KickCrouch;
            }

            break;

        case 1:

            state = StateEnemy.walk;
            break;

        case 2:
            if (isleft)
            {
                state = StateEnemy.dashright;
            }
            if (isright)
            {
                state = StateEnemy.dashleft;
            }


            break;

        case 3:
            state = StateEnemy.jump;

            break;

        case 4:
            state = StateEnemy.KickCrouch;
            break;

        default:
            break;
        }
    }
示例#8
0
 private void OnTriggerEnter(Collider other)
 {
     if (other.CompareTag("Player"))
     {
         state = StateEnemy.die;
         GameController.gameController.DecrementScore();
         FindObjectOfType <Player>().Collided();
         GetComponents <Collider>()[0].isTrigger = false;
         collided = true;
         StartCoroutine("slowDownPlayer");
     }
 }
示例#9
0
    void WalkThink()
    {
        timethink += Time.deltaTime;

        if (timethink > 1)
        {
            state = StateEnemy.walk;
        }
        else
        {
            state = StateEnemy.idle;
        }
    }
示例#10
0
    protected virtual void Start()
    {
        agent = GetComponent <NavMeshAgent>();
        agent.updateRotation = false;

        lastStateEnemy           = StateEnemy.STARTING;
        selectorStartingPosition = false;
        initTimeStarting         = timeStarting;
        player           = GameObject.FindGameObjectWithTag("Player");
        startingPosition = gameObject.transform.position;
        childRenderer    = gameObject.transform.GetChild(0).GetComponent <Renderer>();
        actualMaterial   = materialOriginal;
    }
示例#11
0
 // Start is called before the first frame update
 void Update()
 {
     if (transform.position.z - player.transform.position.z < 15 && state != StateEnemy.die)
     {
         state = StateEnemy.following;
     }
     Vector3.Distance(player.transform.position, transform.position);
     if (FindObjectOfType <Player>().transform.position.z > this.transform.position.z + 5)
     {
         GameController.gameController.IncrementScore();
         Destroy(gameObject);
     }
     checkState();
 }
示例#12
0
 public void CheckStateEnemy()
 {
     if (stateEnemy == StateEnemy.Stunt)
     {
         if (timeDelayStune > 0)
         {
             timeDelayStune = timeDelayStune - Time.deltaTime;
         }
         else if (timeDelayStune <= 0)
         {
             stateEnemy = StateEnemy.none;
             animator.SetBool("Idle", true);
         }
     }
 }
示例#13
0
        /// <summary>
        /// 敵機を作成します。
        /// </summary>
        /// <param name="speed">基準速度。</param>
        public void create(float speed)
        {
            bool created    = false;
            int  percentage = random.Next(denominator);

            for (int i = enemyTypeList.Length; !created && --i >= 0;)
            {
                StateEnemy state = enemyTypeList[i];
                percentage -= state.percentage;
                created     = percentage < 0;
                if (created)
                {
                    create(speed, state);
                }
            }
        }
示例#14
0
        /// <summary>
        /// 敵機を作成します。
        /// </summary>
        /// <param name="speed">基準速度。</param>
        /// <param name="state">敵機の状態。</param>
        public void create(float speed, StateEnemy state)
        {
            Character chr = null;

            for (int i = tasks.Count; chr == null && --i >= 0;)
            {
                Character item = tasks[i];
                if (!item.contains)
                {
                    chr = item;
                }
            }
            if (chr == null)
            {
                chr = new Character();
                tasks.Add(chr);
            }
            chr.velocity  = Vector2.UnitX * speed;
            chr.nextState = state;
        }
示例#15
0
    void Think()
    {
        timethink += Time.deltaTime;

        if (timethink > 2)
        {
            if (isleft)
            {
                state = StateEnemy.dashleft;
            }
            if (isright)
            {
                state = StateEnemy.dashright;
            }
        }
        else
        {
            state = StateEnemy.idle;
        }
    }
示例#16
0
    IEnumerator movmentUp()
    {
        changeMaterial(materialOriginal);
        //Speed = time * dist; we know the speed and the dist;
        float totalTime = 1f;
        float time      = 0;

        gameObject.transform.LookAt(Vector3.forward + gameObject.transform.position);
        changeMaterial(materialOriginal);
        while (time <= totalTime)
        {
            time += Time.deltaTime;
            gameObject.transform.position = Vector3.Lerp(gameObject.transform.position, waypointRespown, curveLeaveRespown.Evaluate(time));
            yield return(null);
        }
        gameObject.transform.position = waypointRespown;
        lastStateEnemy = stateEnemy;
        stateEnemy     = StateEnemy.ATTACKING;
        agent.enabled  = true;
        agent.speed    = speedAttackingStarting;
    }
示例#17
0
 protected void starting()
 {
     if (agent.hasPath == false && agent.pathPending == false)
     {
         if (selectorStartingPosition)
         {
             agent.SetDestination(waypointStarting1);
         }
         else
         {
             agent.SetDestination(waypointStarting2);
         }
         selectorStartingPosition = !selectorStartingPosition;
     }
     timeStarting -= Time.deltaTime;
     if (timeStarting < 0)
     {
         lastStateEnemy = StateEnemy.STARTING;
         stateEnemy     = StateEnemy.FIRSTWAY;
     }
 }
示例#18
0
    /// <summary>
    /// Изменение состояния призрака
    /// </summary>
    /// <param name="newState"></param>
    public void ChangeState(StateEnemy newState)
    {
        if (state == newState)
        {
            return;
        }
        if (state == StateEnemy.Death)
        {
            mr.enabled           = true;
            myTransform.position = startPosition;
            ignoreWalls          = false;
        }
        switch (newState)
        {
        case StateEnemy.Normal:
            mr.sharedMaterial = Resources.Load("Materials/MatGhost") as Material;
            speed             = defaultSpeed;
            break;

        case StateEnemy.Afraid:
            mr.sharedMaterial = Resources.Load("Materials/MatAfraidGhost") as Material;
            speed             = defaultSpeed * 1.5f;
            timeOfFright      = 15;
            break;

        case StateEnemy.Death:
            mr.enabled    = false;
            direction     = (startPosition - myTransform.position).normalized;
            nextDirection = direction;
            SetRotation();
            ignoreWalls = true;
            break;

        case StateEnemy.Chase:
            speed     = GameLogic.player._getSpeed;
            chaseTime = 5;
            break;
        }
        state = newState;
    }
示例#19
0
 public Enemy()
 {
     Health = MaxHealth;
     State  = StateEnemy.Patrol;
 }
示例#20
0
    void CheckChangeState()
    {
        switch (currentState)
        {
        case StateEnemy.NONE:
        {
            break;
        }

        case StateEnemy.PATROL:
        {
            if (Vector3.Distance(this.transform.position, playerTransform.position) <= maxDistanceToPlayer)
            {
                //Current % of Life
                currentPercentLife = (life / maxLife) * 100;

                if (currentPercentLife >= lifeThreshold)
                {
                    countDownToAttack = timeToAttack;
                    //Debug.Log("EL ESTADO ACTUAL ES SEEK");
                    currentState = StateEnemy.SEEK;
                    agent.speed  = speed * 2;
                }
                else
                {
                    countDownToAttack = timeToAttack;
                    //Debug.Log("EL ESTADO ACTUAL ES FLEE");
                    currentState = StateEnemy.FLEE;
                    agent.speed  = speed * 2;
                }
            }
            break;
        }

        case StateEnemy.SEEK:
        {
            //Distance to Player
            if (Vector3.Distance(this.transform.position, playerTransform.position) >= maxDistanceToPlayer)
            {
                countDownToAttack = timeToAttack;

                //Debug.Log("EL ESTADO ACTUAL ES PATROL");
                currentState = StateEnemy.PATROL;
                agent.speed  = speed;
                UpdatePatrolPoint();
            }

            //Current % of Life
            currentPercentLife = (life / maxLife) * 100;

            if (currentPercentLife <= lifeThreshold)
            {
                countDownToAttack = timeToAttack;

                //Debug.Log("EL ESTADO ACTUAL ES FLEE");
                currentState = StateEnemy.FLEE;
            }

            break;
        }

        case StateEnemy.FLEE:
        {
            if (Vector3.Distance(this.transform.position, playerTransform.position) >= maxDistanceToPlayer)
            {
                countDownToAttack = timeToAttack;

                //Debug.Log("EL ESTADO ACTUAL ES PATROL");
                currentState = StateEnemy.PATROL;
                agent.speed  = speed;
                UpdatePatrolPoint();
            }

            //Current % of Life
            currentPercentLife = (life / maxLife) * 100;

            if (currentPercentLife >= lifeThreshold)
            {
                countDownToAttack = timeToAttack;

                //Debug.Log("EL ESTADO ACTUAL ES SEEK");
                currentState = StateEnemy.SEEK;
            }
            break;
        }

        default:
        {
            break;
        }
        }
    }
示例#21
0
    // Update is called once per frame
    void Update()
    {
        if (stopUpdating)
        {
            return;              //Stop Updating and waiting Destroy
        }
        if (_StatusEnemy.IsDead) //On Dead
        {
            _NavMeshAgent.Stop();
            _SpawningEnemy.enemyDie(gameObject.name);
            stopUpdating = true;
            return;
        }

        switch (_StateEnemy)
        {
        case StateEnemy.AttackTarget:
            // If target lost or target is dead then start search new target
            if (_StatusEnemy.TargetStatus == null || _StatusEnemy.TargetStatus.IsDead)
            {
                _Animator.SetBool("BasicAttackBool", false);
                targetTransform = null;
                _StateEnemy     = StateEnemy.SearchTarget;
                _NavMeshAgent.ResetPath();
                return;
            }
            //If can attack target
            if (Vector3.Distance(transform.position, targetTransform.position) < _NavMeshAgent.stoppingDistance)
            {
                LookAtTarget();
                _Animator.SetBool("BasicAttackBool", true);
            }
            else                 // else: target a long way then move
            {
                _Animator.SetBool("BasicAttackBool", false);
                _NavMeshAgent.SetDestination(targetTransform.position);
            }
            break;

        case StateEnemy.SearchTarget:
            //If there is target
            if (_StatusEnemy.TargetStatus != null)
            {
                targetTransform = _StatusEnemy.TargetStatus.transform;
                _StateEnemy     = StateEnemy.AttackTarget;
            }
            else                 //else: start Stay on point
            {
                timeleftSearch = Time.time + timeDelayOnPosition;
                _StateEnemy    = StateEnemy.StayOnPosition;
            }
            break;

        case StateEnemy.StayOnPosition:
            //If there is target
            if (_StatusEnemy.TargetStatus != null)
            {
                targetTransform = _StatusEnemy.TargetStatus.transform;
                _StateEnemy     = StateEnemy.AttackTarget;
                //else: if it time chenge position
            }
            else if (timeleftSearch < Time.time)
            {
                _NavMeshAgent.SetDestination(_SpawningEnemy.getRandomPosition());
                _StateEnemy = StateEnemy.SearchTarget;
            }
            break;
        }

        //Chtngt animation: Stop or move
        if (_NavMeshAgent.velocity == Vector3.zero)
        {
            _Animator.SetFloat("Move", 0.0f);
        }
        else
        {
            _Animator.SetFloat("Move", 0.5f);
        }



        //// here we check whether enemy has reached its NavMesh destination or not.
        //if (DestinationReachedBool)
        //{
        //    _Animator.SetFloat("Move", 0.0f);
        //}
        //// if destination has not been reached enemy start moving. Here and only here actuall movement is implemented
        //else
        //{
        //    _Animator.SetFloat("Move", 0.5f);
        //    ResetTriggers();
        //}


        //if (Physics.Raycast(colliderSightRange.transform.position, targetObj.transform.position - transform.position, out hitEnemy, 55f, maskCombinedEnemySight))
        //{
        //    if (hitEnemy.transform.tag == "Player")
        //    {
        //if (_StatusEnemy.AiType == StatusEnemy.AiTypes.Melee)
        //{
        //    _NavMeshAgent.SetDestination(targetObj.transform.position);
        //    if (DestinationReachedBool) // && CanAttackTarget() - delete
        //    {
        //        UseBasicAttack(true);
        //        targetAttacking = true;
        //        //_Animator.SetTrigger("Atack");
        //    }

        //}

        //if (_StatusEnemy.AiType == AiTypes.Range)
        //{
        //    FBCheckState();
        //    if (currentAiState == "FB_FollowPlayer")
        //    {
        //        SetDestinationCustomRanged();
        //    }
        //    if (currentAiState == "FB_CastFB")
        //    {
        //        CastFireball();
        //    }
        //    if (currentAiState == "FB_GetAway")
        //    {
        //        SetDestinationCustomRanged();
        //    }
        //}


        //if (animator.GetFloat("Move") == 0.0 && !animator.GetCurrentAnimatorStateInfo(0).IsName("atack2"))
        //{
        //    LookAtTarget();
        //}
    }
示例#22
0
 public Enemy(float health)
 {
     Health = health;
     State  = StateEnemy.Patrol;
 }