public void Update() { m_path = Pather.PathVia; transform.position = m_currentPosition; m_ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Input.GetMouseButtonDown(1)) { if (Physics.Raycast(m_ray, out m_hit, 10000, (1 << 9))) { Pather.m_start = GetClosestNode(); Pather.m_end = m_hit.transform.GetComponent <Node>(); m_currNode = 0; Pather.ComputePath(); } } if (Input.GetKeyDown(KeyCode.C)) { started = true; } if (started) { m_graph.ClearGraph(); m_graph = new Graph(Physics.OverlapSphere(new Vector3(720, 0, 736), 96)); GraphNode start = new GraphNode(); GraphNode end = new GraphNode(); foreach (GraphNode gnode in m_graph.GraphNodes) { if (gnode.Type == GraphNode.NodeType.NT_Door) { start = gnode; } if (gnode.Type == GraphNode.NodeType.NT_Target) { end = gnode; } if (start.m_AdjacentNodes != null && end.m_AdjacentNodes != null) { if (start.Type == GraphNode.NodeType.NT_Door && end.Type == GraphNode.NodeType.NT_Target) { break; } } } m_graphPath = m_astar.CalculateEdgeBasedPath(start, end); planned = true; m_currNode = 0; m_currAction = 0; started = false; } if (planned) { ExecutePlan(); } if (m_canMove) { MoveAlongPath(); } if (m_LastLook != Vector3.zero && m_LastLook - m_currentPosition != Vector3.zero) { m_targetRotation = Quaternion.LookRotation((m_LastLook) - m_currentPosition, Vector3.up); } if (m_lastPosition != m_currentPosition) { animation.Play("Walk"); } else { animation.Stop("Walk"); } transform.rotation = Quaternion.Slerp(transform.rotation, m_targetRotation, m_rotationRate * Time.deltaTime); m_lastPosition = m_currentPosition; }