This repository has been archived on 2024-11-28. You can view files and clone it, but cannot push or open issues or pull requests.
PMC_Projekt/ProjektUnity/Assets/Enemy 2/BasicEnemy/BasicEnemy.cs

75 lines
1.6 KiB
C#
Raw Normal View History

2024-09-05 21:10:50 +02:00
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);
}
}