Advertisement
GUPPYYYY

ai chase

Sep 25th, 2024
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class AiChase : MonoBehaviour
  6. {
  7. public GameObject player;
  8. public float speed;
  9. private float distance;
  10. void Start()
  11. {
  12.  
  13. }
  14.  
  15. // Update is called once per frame
  16. void Update()
  17. {
  18. distance = Vector2.Distance(transform.position, player.transform.position);
  19. Vector2 direction = player.transform.position - transform.position;
  20. transform.position = Vector2.MoveTowards(this.transform.position, player.transform.position, speed * Time.deltaTime);
  21. }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement