// Use this for initialization void Start() { jumpCounter = Random.Range(3, 11); agent.speed = patrolSpeed; medMovement.Patrol(); medSounds.PlayTrack(4); }
public IEnumerator Jump(Vector3 startPos, bool onRoof) { Vector3 jumpPoint; if (!onRoof) { jumpPoint = new Vector3(transform.position.x, 14, transform.position.z); } else { jumpPoint = new Vector3(transform.position.x, 0, transform.position.z); } bool wait = false; if (onRoof) { Debug.Log("Checking below"); RaycastHit hit; Collider[] cols; if (Physics.Raycast(transform.position, transform.up * -1, out hit)) { if (hit.transform.tag == "Player") { wait = true; } else { cols = Physics.OverlapSphere(new Vector3(transform.position.x, 0, transform.position.z), scanRadius); for (int i = 0; i < cols.Length; i++) { if (cols [i].tag == "Player") { wait = true; } } } } } if (wait) { Debug.Log("Waiting to jump"); medSounds.PlayTrack(2); yield return(new WaitForSeconds(5.0f)); } if (nMA.enabled) { nMA.enabled = false; } float t = 0; while (t < 1.0f) { t += Time.deltaTime * 5; transform.position = Vector3.Lerp(startPos, jumpPoint, t); //transform.eulerAngles = Vector3.Lerp(transform.eulerAngles, new Vector3(180, transform.eulerAngles.y, transform.eulerAngles.z), t); yield return(null); } nMA.enabled = true; yield return(new WaitForSeconds(0.5f)); Patrol(); }