Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class EnemyRange : MonoBehaviour {
  6.  
  7. public float speed;
  8. public Transform player;
  9.  
  10. private Animator animator;
  11.  
  12.  
  13. void Start()
  14. {
  15.  
  16. }
  17.  
  18.  
  19. void FixedUpdate()
  20. {
  21.  
  22. }
  23.  
  24.  
  25. private void OnTriggerStay(Collider other)
  26. {
  27. if (other.tag == "MainCharacter")
  28.  
  29. {
  30. transform.position = Vector3.MoveTowards(transform.position,
  31. player.position, speed
  32. * Time.deltaTime);
  33. }
  34. else
  35. {
  36. animator.SetBool("isIdle", true);
  37. }
  38.  
  39. }
  40.  
  41. public float speed;
  42. public float range;
  43. public Transform player;
  44.  
  45.  
  46.  
  47. void Start()
  48. {
  49.  
  50. }
  51.  
  52.  
  53. void FixedUpdate()
  54. {
  55. if (Vector3.Distance(player.position, transform.position) <= range)
  56. Debug.Log("In Range" + other.name);
  57.  
  58. {
  59. transform.position = Vector2.MoveTowards(transform.position,
  60. player.position, speed *
  61. Time.deltaTime);
  62. }
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement