Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Enemy : MonoBehaviour
  6. {
  7. // Start is called before the first frame update
  8. private Rigidbody enemyRB;
  9. private GameObject player;
  10. private float speed = 3.0f;
  11.  
  12. void Start()
  13. {
  14. enemyRB = GetComponent<Rigidbody>();
  15. player = GameObject.Find("Player");
  16. }
  17.  
  18. // Update is called once per frame
  19. void Update()
  20. {
  21. var lookDirection = (player.transform.position - transform.position).normalized;
  22. enemyRB.AddForce(lookDirection * speed);
  23.  
  24. if(transform.position.y < -10)
  25. {
  26. Destroy(gameObject);
  27. }
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement