Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Enemy : MonoBehaviour
- {
- // Start is called before the first frame update
- private Rigidbody enemyRB;
- private GameObject player;
- private float speed = 3.0f;
- void Start()
- {
- enemyRB = GetComponent<Rigidbody>();
- player = GameObject.Find("Player");
- }
- // Update is called once per frame
- void Update()
- {
- var lookDirection = (player.transform.position - transform.position).normalized;
- enemyRB.AddForce(lookDirection * speed);
- if(transform.position.y < -10)
- {
- Destroy(gameObject);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement