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
- {
- public float speed = 3.0f;
- private Rigidbody enemyRb;
- private GameObject player;
- void Start()
- {
- enemyRb = GetComponent<Rigidbody>();
- player = GameObject.Find("Player");
- }
- void Update()
- {
- Vector3 lookDirection = (player.transform.position - transform.position).normalized;
- enemyRb.AddForce(lookDirection * speed);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement