Skip to content
Permalink
5482baf0d2
Go to file
 
 
Cannot retrieve contributors at this time
76 lines (60 sloc) 2.18 KB
using UnityEngine;
using System.Collections;
public class EnemyMilitia : MonoBehaviour
{
public Ray ray;
public GameObject player;
public bool canSee;
public float distance;
public float speed;
public int morale = 1;
// Update is called once per frame
void Update()
{
distance = Vector3.Distance(player.transform.position, gameObject.transform.position);
speed = distance * 1.1f;
RaycastHit hit;
ray = new Ray(gameObject.transform.position, new Vector3(gameObject.transform.position.x, gameObject.transform.position.y, gameObject.transform.position.z - 4));
if (Physics.Raycast(ray, out hit))
{
if (hit.collider.tag == "Player")
{
Debug.Log("Hit, hit, damage report");
canSee = true;
ray = new Ray(gameObject.transform.position, new Vector3(gameObject.transform.position.x, gameObject.transform.position.y, gameObject.transform.position.z - 4));
}
if (hit.collider.tag != "Player")
{
Debug.Log("No Joy");
canSee = false;
ray = new Ray(gameObject.transform.position, new Vector3(gameObject.transform.position.x, gameObject.transform.position.y, gameObject.transform.position.z - 4));
}
}
if (canSee == true)
{
iTween.MoveTo(gameObject, player.transform.position, speed);
}
if (canSee == false)
{
iTween.MoveTo(gameObject, new Vector3(gameObject.transform.position.x + 0.01f, gameObject.transform.position.y, gameObject.transform.position.z + .01f), 1);
}
//MOrale===================
if (morale == 0)
{
iTween.MoveTo(gameObject, new Vector3(gameObject.transform.position.x + 5f, gameObject.transform.position.y, gameObject.transform.position.z + 5f), 1);
}
}
void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.tag == "Player")
{
Debug.Log("Ouch!");
}
}
//Button
public void BreakMorale()
{
Debug.Log("Milita Broken!");
morale = 0;
}
}
You can’t perform that action at this time.