private void MoveBack() { GameObject[] adjacent; List <GameObject> possibleTargets = new List <GameObject>(); adjacent = currentLight.GetComponentInParent <lightSourceController>().adjacentSources; foreach (GameObject lamp in adjacent) { int lightType = lamp.GetComponentInParent <lightSourceController>().getCurrentLightType(); if (lightType == 1 || lightType == 2) { possibleTargets.Add(lamp); } } if (possibleTargets.Count > 0) { //always go to the latest light, if possible if (latestLight != null && (possibleTargets.Contains(latestLight) && !history.Contains(latestLight))) //not one we have visited { targetLight = latestLight; } else { //targetLight = possibleTargets[0]; float l = 0; GameObject tg = null; foreach (GameObject g in possibleTargets) { lightSourceController ls = g.GetComponent <lightSourceController>(); if (ls.getTimeRemaining() > l) { l = ls.getTimeRemaining(); tg = g; } } targetLight = tg; } nav.SetDestination(targetLight.transform.position - offset); anim.SetBool("isMoving", true); // if (startingPoint != null) // Destroy(startingPoint); } }
private void MoveToTarget() { //Debug.Log("move to target normal"); GameObject[] adjacent; List <GameObject> possibleTargets = new List <GameObject>(); if (currentLight == null) { adjacent = startAdjacent; } else { adjacent = currentLight.GetComponentInParent <lightSourceController>().adjacentSources; } foreach (GameObject lamp in adjacent) { int lightType = lamp.GetComponentInParent <lightSourceController>().getCurrentLightType(); if (lightType == 1 || lightType == 2) { possibleTargets.Add(lamp); } } // remove any past nodes from possible move list foreach (GameObject g in history) { if (possibleTargets.Contains(g)) { // Debug.Log("removing " + g); possibleTargets.Remove(g); } } if (possibleTargets.Count > 0) { // foreach(GameObject g in possibleTargets) // Debug.Log(g); //always go to the latest light, if possible if (latestLight != null && (possibleTargets.Contains(latestLight) && !history.Contains(latestLight))) //not one we have visited { targetLight = latestLight; } /* * //if the justVisited in the targetLamps array, ignore it * else if (possibleTargets.Contains(justVisited)){ * possibleTargets.Remove(justVisited); * } */ //else go to the default one else { // after pruning if we still have a light it can go to // if (possibleTargets.Count > 0) { //targetLight = possibleTargets[0]; float l = 0; GameObject tg = null; foreach (GameObject g in possibleTargets) { lightSourceController ls = g.GetComponent <lightSourceController>(); if (ls.getTimeRemaining() > l) { l = ls.getTimeRemaining(); tg = g; } } targetLight = tg; // } } nav.SetDestination(targetLight.transform.position - offset); if (nav.speed != fastSpeed && targetLight.GetComponent <lightSourceController>().getCurrentLightType() == 2) { //Debug.Log("increasing speed"); movingToTravLight = true; nav.speed = fastSpeed; } anim.SetBool("isMoving", true); if (startingPoint.activeInHierarchy) { startingPoint.SetActive(false); } } /* * else * { * anim.SetBool("isMoving", false); * } */ }