// Update is called once per frame
 void Update()
 {
     if (GameController.CurrentGamePlayStatus != GameController.GameplayStatus.Play)
     {
         return;
     }
     if (this.Target != null)
     {
         if (this.Target.transform.position.x < this.transform.position.x && this.CurrentLookingTo != LookingTo.Left)
         {
             this.CurrentLookingTo           = LookingTo.Left;
             this.transform.localEulerAngles = new Vector3(0, 0, 0);
         }
         else
         if (this.Target.transform.position.x > this.transform.position.x && this.CurrentLookingTo != LookingTo.Right)
         {
             this.CurrentLookingTo           = LookingTo.Right;
             this.transform.localEulerAngles = new Vector3(0, 180, 0);
         }
         //var fwd = transform.rotation * Vector3.forward;
         //Debug.DrawRay(this.transform.position, fwd, Color.yellow);
         //Ray newRay = new Ray(this.transform.position, fwd);
         float distanceToPlayer = Vector3.Distance(this.gameObject.transform.position, this.Target.transform.position);
         this.DistanceToTarget = distanceToPlayer;
         if (distanceToPlayer > this.MinimumAllowedDistance)
         {
             NavigateToPlayer();
         }
         if (Time.time > (this.lastTimeAttacked + AttackInterval) && Mathf.Floor(distanceToPlayer) == MinimumAllowedDistance)
         {
             DamagePlayer();
             this.lastTimeAttacked = Time.time;
         }
     }
 }
示例#2
0
    // Update is called once per frame
    void Update()
    {
        if (GameController.CurrentGamePlayStatus != GameController.GameplayStatus.Play)
        {
            return;
        }
        float   h         = Input.GetAxis("Horizontal");
        float   v         = Input.GetAxis("Vertical");
        Vector3 direction = this.transform.localScale;

        if ((h != 0 || v != 0) && Input.GetKeyUp(KeyCode.Z) == false)
        {
            SetTrigger("Mover");
        }
        if (h < 0 && this.CurrentLookingTo != LookingTo.Left)
        {
            this.CurrentLookingTo = LookingTo.Left;
            //this.gameObject.GetComponent<Renderer>().material.color = Color.blue;
            transform.localEulerAngles = new Vector3(0, -90, 0);
            //direction = new Vector3(this.transform.localScale.x*-1, 1, 1);
            //this.transform.localScale = direction;
        }
        else
        if (h > 00 && this.CurrentLookingTo != LookingTo.Right)
        {
            this.CurrentLookingTo = LookingTo.Right;
            //this.gameObject.GetComponent<Renderer>().material.color = Color.red;
            transform.localEulerAngles = new Vector3(0, 90, 0);
            //direction = new Vector3(this.transform.localScale.x*-1,1,1);
            //this.transform.localScale = direction;
        }
        Vector3 dest = this.transform.position;

        dest.x += h;
        dest.z += v;
        //Debug.LogFormat("Moving To: {0},{1}, {2}", dest.x, dest.y, dest.z);
        this.transform.position = Vector3.MoveTowards(this.transform.position, dest, Speed * Time.deltaTime);
        var fwd = transform.rotation * Vector3.forward;

        Debug.DrawRay(this.transform.position, fwd, Color.black);
        if (Input.GetKeyUp(KeyCode.Z))
        {
            SetTrigger("Atacar");
            EnemyHunger closestEnemy = this.EnemyController.SpawnedEnemies.OrderBy(d => d.GetDistanceToTarget()).FirstOrDefault();
            if (closestEnemy != null && closestEnemy.IsValidTarget)
            {
                ApplyAttack(fwd, closestEnemy.gameObject, closestEnemy);
            }
            Ray        newRay         = new Ray(this.transform.position, fwd);
            RaycastHit raycastHitInfo = new RaycastHit();
            //AttackByRaycasting(ref fwd, ref newRay, ref raycastHitInfo);
            //Debug.LogFormat("{0},{1}, {2}", fwd.x, fwd.y, fwd.z);
            //this.transform.position += fwd;
        }
    }