// Update is called once per frame
 void Update()
 {
     if (brain.Player != null)
     {
         sightline = Physics2D.Raycast(attackpoint.position, brain.Player.transform.position - transform.position);
         var dir   = brain.Player.transform.position - transform.position;
         var angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
         transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
         if (Vector2.Distance(brain.Player.transform.position, transform.position) < disAway)
         {
             if (sightline.collider.CompareTag("Player"))
             {
                 transform.position = Vector3.MoveTowards(gameObject.transform.position, brain.Player.transform.position, brain.Speed * Time.deltaTime);
             }
             else
             {
                 return;
             }
         }
         if (Vector2.Distance(brain.Player.transform.position, transform.position) < brain.attackrad * 2)
         {
             combat.attack();
         }
     }
     else
     {
         brain.findP();
     }
 }
Exemple #2
0
 // Update is called once per frame
 void Update()
 {
     down     = Physics2D.Raycast(pathfinder.transform.position, -Vector2.up, brain.attackrad);
     leftRigt = Physics2D.Raycast(pathfinder.transform.position, moveDire * Vector2.right, brain.attackrad);
     if (down.collider != null && leftRigt.collider == null)
     {
         transform.Translate(brain.Speed * Time.deltaTime, 0, 0);
     }
     else
     {
         if (leftRigt.collider != null)
         {
             if (leftRigt.collider.CompareTag("Player"))
             {
                 combat.attack();
             }
             else
             {
                 Flip();
             }
         }
         else
         {
             Flip();
         }
     }
     Debug.DrawRay(pathfinder.transform.position, -Vector2.up, color: Color.blue, brain.attackrad);
     Debug.DrawRay(pathfinder.transform.position, moveDire * Vector2.right, color: Color.blue, brain.attackrad);
 }