private void Start() { if (followPlayer) { target = GameObject.FindGameObjectWithTag("Player").transform.position; } path = pm.FindPath(transform.position, target); }
public bool SetDestination(Vector3 worldSpaceDestination, bool local = false) { if (pathfindingManager == null) { Debug.LogError("No pathfinding manager setup in pathfinding agent: " + name); return(false); } m_CurrentIndex = 0; m_Alpha = 0.0f; m_HasPath = pathfindingManager.FindPath(transform.position, worldSpaceDestination, ref m_Path, local); if (m_HasPath) { m_Local = local; m_CurrentIndex = 0; m_Alpha = 0.0f; } // Added by Chris to enable looting when already standing near object else if (pathfindingManager.GetNode(transform.position) == pathfindingManager.GetNode(worldSpaceDestination)) { onReachedDestination.Invoke(); } return(m_HasPath); }
private void Update() { if (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit result; if (Physics.Raycast(ray, out result, Mathf.Infinity, tileLayer)) { if (Input.GetMouseButtonDown(0)) { Tile tile = result.collider.GetComponent <Tile>(); if (tile != null) { tile.ToggleObstacle(); } } if (Input.GetMouseButtonDown(1)) { Vector3 destPosition = result.collider.transform.position; Node deptNode = pathfindingManager.PositionToNode(agent.transform.position); Node destNode = pathfindingManager.PositionToNode(destPosition); agent.FollowPath(pathfindingManager.FindPath(deptNode, destNode)); } } } }