private void SummonSkeleton() { Vector3 spawnpoint = player.transform.position + new Vector3(spawnDistance * Mathf.Cos(UnityEngine.Random.Range(0, Mathf.PI / 2)), 0, spawnDistance * Mathf.Sin(UnityEngine.Random.Range(0, Mathf.PI / 2))); NavEntityBehaviour Skeleton = Instantiate(SkeletonPrefab, spawnpoint, Quaternion.identity).GetComponent <NavEntityBehaviour>(); AliveSkeletons.Add(Skeleton); instance.AvailableSkeletons--; playerEntity.TakeDamage(SkeletonLifeCost, null); }
/// <summary> /// Checks for an entity in it's view distance. /// </summary> /// <param name="Tag">Tag of the entity. The GameObject tagged must have an Entity component (such as NavEntityBehaviour)</param> /// <returns>The first entity that's found.</returns> Entity CheckForEntity(string Tag) { Collider[] cols = Physics.OverlapSphere(transform.position, viewDistance); NavEntityBehaviour FoundEntity = null; foreach (Collider col in cols) { if (col.transform.root.gameObject.CompareTag(Tag)) { Debug.Log("Found an enemy withing viewing radius: " + col.transform.root.name); FoundEntity = col.transform.root.GetComponentInParent <NavEntityBehaviour>(); if (FoundEntity == null) { Debug.LogWarning("It's NavEntityBehaviour is null!"); } break; } } if (FoundEntity == null) { return(FoundEntity); } // It's in the viewing zone, but... Can we actually see it? Vector3 direction = FoundEntity.transform.position - this.transform.position; RaycastHit hit; // Does the ray intersect any objects? (Added offset to exclude the player) if (Physics.Raycast(transform.position + direction * 0.25f + Vector3.up * 0.25f, direction, out hit, Mathf.Infinity)) { if (hit.collider.transform.root.gameObject.CompareTag(Tag)) { // We hit the same entity (or one that has the same Tag, so it's the same) return(FoundEntity); } else { return(null); } } else { return(null); } }
public void SetupPlayer(GameObject player) { this.player = player; playerEntity = this.player.GetComponent <NavEntityBehaviour>(); playerEntity.Health = GameProgress.playerHealth == 0 ? MaxPlayerHealth : GameProgress.playerHealth; }