Permalink
Cannot retrieve contributors at this time
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?
Intro_Scritping/Roguelike/Assets/Scripts/EnemySkeleton.cs
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
71 lines (54 sloc)
2.1 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class EnemySkeleton : MonoBehaviour | |
{ | |
public Ray ray; | |
public GameObject player; | |
public bool canSee; | |
public float distance; | |
public float speed; | |
public Vector3 midpoint; | |
// 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); | |
} | |
} | |
void OnCollisionEnter(Collision collision) | |
{ | |
if (collision.gameObject.tag == "Player") | |
{ | |
Debug.Log("Ouch!"); | |
} | |
} | |
} |