25 lines
538 B
C#
25 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);
|
|||
|
}
|
|||
|
}
|