UnityProjekt/Assets/Scripts/EnemyController.cs
2020-11-06 22:30:54 +01:00

24 lines
538 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyController : MonoBehaviour
{
public Transform target;
public float speed;
private Rigidbody2D _rb;
// Start is called before the first frame update
void Start()
{
_rb = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void FixedUpdate()
{
var diff = target.position - transform.position;
diff.Normalize();
_rb.AddForce(diff * speed);
}
}