75 lines
1.6 KiB
C#
75 lines
1.6 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Unity.VisualScripting;
|
|
using UnityEditor;
|
|
using UnityEditor.Callbacks;
|
|
using UnityEngine;
|
|
using UnityEngine.Timeline;
|
|
|
|
public class BasicEnemy : MonoBehaviour
|
|
{
|
|
|
|
[Header("References")]
|
|
public Transform parentTransform;
|
|
public Player playerData;
|
|
public BasicEnemyStateController sc;
|
|
|
|
[Header("Settings")]
|
|
|
|
public float distance;
|
|
public float moveSpeed;
|
|
|
|
[Header("Internal")]
|
|
|
|
public Vector2 targetPosition;
|
|
public Vector2 currentTargetVector;
|
|
public int randomNumber;
|
|
public Vector2 currentVelocity;
|
|
|
|
void Awake()
|
|
{
|
|
currentTargetVector = new Vector2(Random.Range(0,2)*2-1, Random.Range(0,2)*2-1);
|
|
}
|
|
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
|
|
if(Input.GetKeyDown(KeyCode.Q))
|
|
{
|
|
RandomNeighborVector();
|
|
CalculateTargetPosition();
|
|
}
|
|
|
|
MoveToPosition();
|
|
|
|
}
|
|
|
|
void CalculateTargetPosition()
|
|
{
|
|
targetPosition = playerData.playerPosition + currentTargetVector * distance;
|
|
}
|
|
|
|
void RandomNeighborVector()
|
|
{
|
|
if(Random.Range(0,2) == 0)
|
|
{
|
|
currentTargetVector.x = currentTargetVector.x - (currentTargetVector.x * 2);
|
|
}
|
|
else
|
|
{
|
|
currentTargetVector.y = currentTargetVector.y - (currentTargetVector.y * 2);
|
|
}
|
|
}
|
|
|
|
void MoveToPosition()
|
|
{
|
|
parentTransform.position = Vector2.SmoothDamp(transform.position, targetPosition, ref currentVelocity, moveSpeed * Time.deltaTime);
|
|
}
|
|
|
|
}
|