UnityProjekt/Assets/Scripts/EnemyController.cs

25 lines
538 B
C#
Raw Normal View History

2020-11-06 21:30:54 +00:00
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);
}
}