using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SimpleEnemy : MonoBehaviour {
public Transform[] patrolpoints;
int currentPoint;
public float speed=0.05f;
public float sight=5f;
float speedy;
Animator anima;
public GameObject Anger;
// Use this for initialization
void Start () {
anima = GetComponent ();
Anger.SetActive (false);
}
void Awake()
{
StartCoroutine("Patrol");
}
// Update is called once per frame
void Update () {
RaycastHit2D hit = Physics2D.Raycast (transform.position, transform.localScale.x * Vector2.right, sight);
if (hit.collider != null && hit.collider.tag == "Player") {
speedy = speed * 1.25f;
anima.SetBool ("run", true);
Anger.SetActive (true);
}
else {
speedy = speed;
Anger.SetActive (false);
anima.SetBool ("run", false);
}
}
IEnumerator Patrol()
{
while (true){
if (transform.position.x == patrolpoints [currentPoint].position.x)
{
currentPoint++;
}
if (currentPoint >= patrolpoints.Length) {
currentPoint = 0;
}
transform.position=Vector2.MoveTowards(transform.position,new Vector2(patrolpoints[currentPoint].position.x,transform.position.y), speedy);
if(transform.position.x>patrolpoints[currentPoint].position.x)
transform.localScale=new Vector3(-0.5f,0.3f,1);
else if(transform.position.x
↧