2022-04-07 19:22:29 +02:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
2022-05-18 21:56:39 +02:00
|
|
|
public class PatrollingEnemy : Enemy
|
2022-04-07 19:22:29 +02:00
|
|
|
{
|
|
|
|
public Transform[] path;
|
|
|
|
public int currentPoint;
|
|
|
|
public Transform currentGoal;
|
|
|
|
public float roundingDistance;
|
|
|
|
|
|
|
|
private Rigidbody2D myRigidbody;
|
|
|
|
//public Transform target;
|
|
|
|
public Animator anim;
|
|
|
|
|
2022-06-15 16:32:14 +02:00
|
|
|
//isKilled = 0 - mob ALIVE
|
|
|
|
//isKilled = 1 - mob DEAD
|
|
|
|
|
2022-04-07 19:22:29 +02:00
|
|
|
// Start is called before the first frame update
|
|
|
|
void Start()
|
|
|
|
{
|
2022-06-15 16:32:14 +02:00
|
|
|
isKilled = PlayerPrefs.GetInt(enemyName);
|
|
|
|
if(isKilled == 1)
|
|
|
|
{
|
|
|
|
gameObject.SetActive(false);
|
|
|
|
}
|
2022-04-07 19:22:29 +02:00
|
|
|
myRigidbody = GetComponent<Rigidbody2D>();
|
|
|
|
anim = GetComponent<Animator>();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
void Update()
|
|
|
|
{
|
|
|
|
if (Vector3.Distance(transform.position, path[currentPoint].position) > roundingDistance)
|
|
|
|
{
|
|
|
|
Vector3 temp = Vector3.MoveTowards(transform.position, path[currentPoint].position, moveSpeed * Time.deltaTime);
|
|
|
|
//changeAnim(temp - transform.position);
|
|
|
|
myRigidbody.MovePosition(temp);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
changeGoal();
|
|
|
|
}
|
2022-06-21 01:09:06 +02:00
|
|
|
//killing
|
2022-06-15 16:32:14 +02:00
|
|
|
if(gameObject.active == false)
|
|
|
|
{
|
|
|
|
isKilled = 1;
|
|
|
|
PlayerPrefs.SetInt(enemyName, isKilled);
|
|
|
|
}
|
2022-04-07 19:22:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void changeGoal()
|
|
|
|
{
|
|
|
|
if (currentPoint == path.Length - 1)
|
|
|
|
{
|
|
|
|
currentPoint = 0;
|
|
|
|
currentGoal = path[0];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
currentPoint++;
|
|
|
|
currentGoal = path[currentPoint];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|