Skip to content
Permalink
5482baf0d2
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
84 lines (66 sloc) 2.47 KB
using UnityEngine;
using System.Collections;
public class EnemyArcher : MonoBehaviour
{
public Ray ray;
public GameObject player;
public bool canSee;
public float distance;
public float speed;
public Vector3 midpoint;
public int morale = 1;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
distance = Vector3.Distance(player.transform.position, gameObject.transform.position);
midpoint = new Vector3(gameObject.transform.position.x + (player.transform.position.x - gameObject.transform.position.x) / 2, transform.position.y, gameObject.transform.position.z + (player.transform.position.z));
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, midpoint, 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;
}
}