42 lines
884 B
C#
42 lines
884 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
|
|
public class Ennemy : MonoBehaviour
|
|
{
|
|
|
|
[SerializeField]
|
|
bool isStatic = true;
|
|
|
|
[SerializeField]
|
|
float SpeedModifier = 10;
|
|
|
|
Vector3 lastposition;
|
|
|
|
int tickWithoutMoving = 0;
|
|
|
|
void Update()
|
|
{
|
|
if (!isStatic) {
|
|
transform.position += SpeedModifier * transform.forward * Time.deltaTime;
|
|
if(transform.position == lastposition) tickWithoutMoving++;
|
|
lastposition = transform.position;
|
|
if (tickWithoutMoving == 3) transform.forward = -transform.forward ;
|
|
}
|
|
}
|
|
|
|
|
|
private void OnTriggerEnter(Collider other){
|
|
if (other.tag == "Player"){
|
|
if (other.transform.position.y-0.5 > this.gameObject.transform.position.y){
|
|
GetComponent<Killable>().die();
|
|
}
|
|
else {
|
|
other.GetComponent<Killable>().die();
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|