/* * Used to get to the next lamp in sequence * As of rn, not sure if I want this, so obsolete for now */ public GameObject checkLamps() { GameObject currLamp = findCurrentLamp(); int litlamps = litLamps(); lightSourceController lController = currLamp.GetComponentInParent <lightSourceController>(); if (litlamps == 1 && lController.getCurrentLightType() != 0) { return(null); } if (litlamps == 2) { GameObject nextLamp = null; foreach (GameObject lamp in lController.adjacentSources) { int lightType = lController.getCurrentLightType(); if (lightType == 1 || lightType == 2) { nextLamp = lamp; } } return(nextLamp); } return(null); }
public void moveToLamp() { //Debug.Log("in the move to lamp"); if (currentLamp == null) // initial gamestate when monster is first placed { float distance = Mathf.Infinity; foreach (GameObject lamp in lamps) //this part is also not quite working { if (Vector3.Distance(transform.position, lamp.transform.position) < distance) // edge case, does not take into account lit lamp { distance = Vector3.Distance(transform.position, lamp.transform.position); currentLamp = lamp; } } } else //general case of finding lamps { lightSourceController lController = currentLamp.GetComponentInParent <lightSourceController>(); if (lController == null) { Debug.Log("Could not find lightsourcontroller"); } GameObject[] adjacentLamps = lController.getAdjacentSources(); List <GameObject> possibleTargets = new List <GameObject>(); foreach (GameObject adjacentlamp in adjacentLamps) { lightSourceController adjLController = adjacentlamp.GetComponentInParent <lightSourceController>(); int lightType = adjLController.getCurrentLightType(); if (lightType == 1 || lightType == 3) { possibleTargets.Add(adjacentlamp); } } if (lController.getCurrentLightType() == 1 || lController.getCurrentLightType() == 3) //possible bug need to fix when lamps are implemented { currentTarget = transform.position; nav.SetDestination(currentTarget); targetLamp = null; movingToLamp = false; return; } GameObject[] targetLamps = possibleTargets.ToArray(); if (targetLamps.Length == 0) { targetLamps = adjacentLamps; //WILL NEED TO DEBUGGGGGGG //Debug.Log("PLEASE PLACE BREAKPOINT HERE unsure if this will behave correctly"); } int ran = Random.Range(0, targetLamps.Length); //unsure doesnt work with length - 1, tried the remove 1 now it works???!!! targetLamp = targetLamps[ran]; currentTarget = targetLamp.transform.position; nav.SetDestination(currentTarget); movingToLamp = true; } }
public void moveToLamp() { Debug.Log("in here"); GameObject[] lamps = GameObject.FindGameObjectsWithTag("LampLight"); List <GameObject> validLamps = new List <GameObject>(); foreach (GameObject lamp in lamps) { if (Vector3.Distance(transform.position, lamp.transform.position) <= MAX_LD && Vector3.Distance(roamCenterPoint, lamp.transform.position) <= maxRoamDistance) { lightSourceController lController = lamp.GetComponentInParent <lightSourceController>(); if (lController == null) { Debug.Log("Could not find lightsourcontroller"); } int lightType = lController.getCurrentLightType(); // lamp.transform.GetChild(0).GetComponentInChildren<Light>().intensity == 3 && if (lightType == 1 || lightType == 3) //1 is trav, 3 is monster { // lamp is lit if (!lamp.Equals(lastVisited) && lamp.transform.position != currentTarget) { Debug.Log("LAMP IS HERE"); if (lastVisited != null) { lastVisited = findCurrentLamp(); } currentTarget = lamp.transform.position; nav.SetDestination(lamp.transform.position); moving = true; Debug.Log("WATTTTTTT"); return; //should choose a random one } } else { if (!lamp.Equals(lastVisited) && lamp.transform.position != currentTarget) { if (lastVisited != null) { lastVisited = findCurrentLamp(); } validLamps.Add(lamp); } } } } lamps = validLamps.ToArray(); if (lamps.Length != 0) { int ran = Random.Range(0, lamps.Length - 1); GameObject lamp = lamps[ran]; currentTarget = lamp.transform.position; nav.SetDestination(lamp.transform.position); moving = true; return; } }
public void setTarget(GameObject light) { Debug.Log(currentLight); if (currentLight != null) { lightSourceController lController = currentLight.GetComponentInParent <lightSourceController>(); Debug.Log(lController); foreach (GameObject lamp in lController.adjacentSources) { if (lamp.Equals(light)) { lightSourceController lampController = lamp.GetComponentInParent <lightSourceController>(); if (lampController.getCurrentLightType() == 1 || lampController.getCurrentLightType() == 2) { goal = light.transform; target = goal.position; hasTarget = true; } } } } else { if (Vector3.Distance(transform.position, light.transform.position) <= 6f) { lightSourceController lampController = light.GetComponentInParent <lightSourceController>(); if (lampController.getCurrentLightType() == 1 || lampController.getCurrentLightType() == 2) { goal = light.transform; target = goal.position; hasTarget = true; } } } }
//Are there any lights on? private bool anyLightsOn() { GameObject [] lights = GameObject.FindGameObjectsWithTag("LampLight"); foreach (GameObject light in lights) { lightSourceController lsc = light.GetComponent <lightSourceController>(); if (lsc.getCurrentLightType() != 0) { return(true); } } return(false); }
// Update is called once per frame void Update() { if (lightScript.getCurrentLightType() == 0) { my_renderer.material = default_mat; //meshRenderer.enabled = false; } else { meshRenderer.enabled = true; my_renderer.material = lit_mat; my_renderer.material.SetColor("_EmissionColor", lt.color); } }
// Update is called once per frame void Update() { int lightType = LSC.getCurrentLightType(); switch (lightType) { case 0: obj.enabled = false; break; case 1: obj.material = defaultLight; obj.enabled = true; break; case 2: obj.material = travLight; obj.enabled = true; break; case 3: obj.material = monLight; obj.enabled = true; break; } /* * if (parentLight.intensity > 0 && parentLight.enabled == true) * { * obj.material.SetColor("_Color", parentLight.color); * obj.enabled = true; * } * else * { * obj.enabled = false; * } */ }
/* * Returns the number of lamps lit that the traveler could travel to. If it's zero, * traveler's health goes down. */ public int litLamps() { GameObject currLamp = findCurrentLamp(); int litlamps = 0; if (currLamp != null) { lightSourceController lController = currLamp.GetComponentInParent <lightSourceController>(); foreach (GameObject lamp in lController.adjacentSources) { lightSourceController lampController = lamp.GetComponentInParent <lightSourceController>(); if (lampController.getCurrentLightType() != 0) { litlamps++; } } if (lController.getCurrentLightType() != 0) { litlamps++; } return(lController.adjacentSources.Length); } return(0); }
public void isLampLit() { Debug.Log("checking if lamp is lit"); GameObject[] lamps = GameObject.FindGameObjectsWithTag("LampLight"); List <GameObject> validLamps = new List <GameObject>(); foreach (GameObject lamp in lamps) { if (Vector3.Distance(transform.position, lamp.transform.position) <= MAX_LD && Vector3.Distance(roamCenterPoint, lamp.transform.position) <= maxRoamDistance) { lightSourceController lController = lamp.GetComponentInParent <lightSourceController>(); if (lController == null) { Debug.Log("Could not find lightsourcontroller"); } int lightType = lController.getCurrentLightType(); if (lightType == 1 || lightType == 3) { moving = false; } } } }
void Update() { /* * if (Input.GetKeyDown(KeyCode.C)) { * Debug.Log(targetLight); * Debug.Log(currentLight); * } */ if (!closeToExit) { if (targetLight != null && targetLight != currentLight) { //Debug.Log("running first"); //check to see if it turned off lightSourceController lScript = targetLight.GetComponent <lightSourceController>(); // the targte light was turned off before we got there if (lScript.getCurrentLightType() == 0) { //go back to the current light -> have not run find current yet if (currentLight == null) { MoveToTarget(startingPointTransform); targetLight = null; movingBack = true; if (!startingPoint.activeInHierarchy) { startingPoint.SetActive(true); } } else { // Debug.Log("here"); MoveToTarget(currentLight); } return; } } if (!movingBack) { FindCurrent(); } //what if the current light we are at is turned off if (currentLight != null) { lightSourceController currentScript = currentLight.GetComponent <lightSourceController>(); if (currentScript.getCurrentLightType() == 0) { //Debug.Log("running second"); //go back to any adjacent ones MoveBack(); //if not just stay there. return; } } //FindJustVisited(); MoveToTarget(); //Animating(); } if (Vector3.Distance(exitPoint.position, transform.position) < 0.7) { beatLevel = true; Debug.Log("load next"); loadNextLevel(); } // float distRemaining = nav.remainingDistance; //Debug.Log(distRemaining); if (nav.remainingDistance <= nav.stoppingDistance) //nav.remainingDistance == 0)//distRemaining!= Mathf.Infinity && nav.pathStatus == NavMeshPathStatus.PathComplete && // if (nav.pathStatus == NavMeshPathStatus.PathComplete) // if (targetLight != null && Vector3.Distance(transform.position, targetLight.transform.position) < lampDistance && anim.GetBool("isMoving")) { anim.SetBool("isMoving", false); targetLight = null; if (nav.speed > defaultSpeed) { movingToTravLight = false; nav.speed = defaultSpeed; } if (movingBack) { movingBack = false; currentLight = null; } } }
/* * void OnTriggerEnter(Collider other) { * Debug.Log("") * * if (other.tag == "LampLight") { * currentTarget = other.gameObject; * //interactionText.text = "Press X to interact with Light Source"; * interactionPopUp.SetActive(true); * Vector3 popUpLocation = other.gameObject.transform.position; * popUpLocation.y = popUpLocation.y + textVerticalOffset; * popUpController.updateWorldObjectTransform(popUpLocation); * //controlLureImage(); * * lScript = other.GetComponent<lightSourceController>(); * if (lScript == null) * Debug.Log("Could not get lscript"); * * lScript.turnOnWorldPaths(); * lScript.turnOnPaths(); * } * * } */ void OnTriggerStay(Collider other) { if (other.tag == "Traveller" && healUnlocked) { targetTraveller = other.gameObject; travellerHealth tHealth = targetTraveller.GetComponent <travellerHealth>(); if (tHealth == null) { Debug.Log("Could not get traveller health script"); } if (tHealth.currentHealth != tHealth.startingHealth) { canHeal = true; //canHeal = true; //interactionText.text = "Hold X to transfer light to Traveller"; // travHealingBar.SetActive(true); Vector3 popUpLocation = other.gameObject.transform.position; popUpLocation.y = popUpLocation.y + textVerticalOffset; popUpController3.updateWorldObjectTransform(popUpLocation); travHealingBarController.updateWorldObjectTransform(popUpLocation); if (isHealing) { //popUpText3.fontSize = 80; //popUpText3.text = "Healing"; interactionPopUp3.SetActive(false); travHealingBar.SetActive(true); //travhealing } else { interactionPopUp3.SetActive(true); if (pController.getResource() > 0) { popUpText3.fontSize = 80; popUpText3.text = "Hold to Heal"; } else { popUpText3.fontSize = 80; popUpText3.text = "Not Enough!"; } //controlLureImage(); //return; } } else { interactionPopUp3.SetActive(false); travHealingBar.SetActive(false); canHeal = false; } return; } if (other.tag == "LampLight") { //Debug.Log("at lamp light"); if (currentTarget != other.gameObject) //new lamp entered radius but old hasnt left { if (lScript != null) { if (lScript.getCurrentLightType() == 0) { //lScript.setMiniMapPathColor(0); lScript.turnOffPaths(); //Debug.Log("turning off)"); } lScript.turnOffWorldPaths(); lScript.switcherScript.setDefault(); } } currentTarget = other.gameObject; //interactionPopUp.SetActive(true); /* * Vector3 popUpLocation = other.gameObject.transform.position; * popUpLocation.y = popUpLocation.y + textVerticalOffset; * popUpController.updateWorldObjectTransform(popUpLocation); */ lScript = other.GetComponent <lightSourceController>(); if (lScript.getCurrentLightType() != 0 && restrictRecover) { interactionPopUp.SetActive(false); return; } interactionPopUp.SetActive(true); if (lScript == null) { Debug.Log("Could not get lscript"); } lScript.turnOnWorldPaths(); lScript.turnOnPaths(); lScript.switcherScript.sethighlight(); return; } if (other.tag == "Monster") { EnemyMovement monScript = other.gameObject.GetComponent <EnemyMovement>(); if (monScript == null) { Debug.Log("Could not find monscript"); } //monScript.popUp2.SetActive(true); Vector3 popUpLocation = other.gameObject.transform.position; popUpLocation.y = popUpLocation.y + textVerticalOffset; monScript.popUp2.GetComponent <WorldSpaceObjectController>().updateWorldObjectTransform(popUpLocation); } /* * if (other.tag == "Monster" && stunUnlocked) { * * * //currentTarget = other.gameObject; * //targetMonster = other.gameObject; * //interactionText.text = "Press X to stun Monster"; * //interactionPopUp2.SetActive(true); * //Vector3 popUpLocation = other.gameObject.transform.position; * //popUpLocation.y = popUpLocation.y +textVerticalOffset; * ////popUpController2.updateWorldObjectTransform(popUpLocation); * //controlLureImage(); * //return; * * * * * EnemyMovement monScript = other.gameObject.GetComponent<EnemyMovement>(); * if (monScript == null) { * Debug.Log("Could not find monscript"); * } * //else * if (!monScript.getIsStunned()) { * * if (!monstersInRange.Contains(other.gameObject)){ * monstersInRange.Add(other.gameObject); * } * monScript.popUp.SetActive(true); * // monScript.popUp2.SetActive(false); * Vector3 popUpLocation = other.gameObject.transform.position; * popUpLocation.y = popUpLocation.y +textVerticalOffset; * monScript.popUp.GetComponent<WorldSpaceObjectController>().updateWorldObjectTransform(popUpLocation); * Text monText = monScript.popUp.GetComponentInChildren<Text>(); * if (pController.getResource() >= 20){ // change to public var later * * monText.fontSize = 100; * monText.text = "Stun"; * } * * else { * monText.fontSize = 80; * monText.text = "Not Enough!"; * } * * return; * * } * else { * monScript.popUp.SetActive(false); * monScript.popUp2.SetActive(true); * * Vector3 popUpLocation = other.gameObject.transform.position; * popUpLocation.y = popUpLocation.y + textVerticalOffset; * monScript.popUp2.GetComponent<WorldSpaceObjectController>().updateWorldObjectTransform(popUpLocation); * * monstersInRange.Remove(other.gameObject); * } * * * * * } * */ }
// Update is called once per frame void Update() { if (Time.timeScale == 0f || inTutorial) { if (isHealing) { heldDuration = 0f; isHealing = false; if (targetTraveller != null) { travellerHealth tScript = targetTraveller.GetComponent <travellerHealth>(); if (tScript.isHealingEffectOn()) { tScript.stopHealingEffect(); healingSFX.Stop(); } } if (travHealingBar.activeInHierarchy) { travHealingBar.SetActive(false); } // moved outside of off claue above (if you move away from trav it'll loop infintely) anim.SetBool("isHealing", false); } return; } if (Input.GetButtonDown("Circle") || Input.GetKeyDown(KeyCode.Space)) { isHealing = true; if (targetTraveller != null && targetTraveller.tag == "Traveller") { travellerHealth tScript = targetTraveller.GetComponent <travellerHealth>(); if (tScript.currentHealth != tScript.startingHealth) { tScript.startHealEffect(); healingSFX.Play(); } } } if (Input.GetButton("Circle") || Input.GetKey(KeyCode.Space)) { heldDuration += Time.deltaTime; if (heldDuration > 0.5f) //&& !setHealing) { //start healing //setHealing = true; { if (targetTraveller != null && targetTraveller.tag == "Traveller") { travellerHealth tScript = targetTraveller.GetComponent <travellerHealth>(); currentHealTime += Time.deltaTime; if (canHeal) { if (pController.getResource() > 0 && currentHealTime >= timeToHeal) { anim.SetBool("isHealing", true); //tScript.increaseCape(); tScript.GetHeal(1); pController.addResource(-1f); currentHealTime = 0f; } return; } //stop healing if we cannot heal else { if (tScript.isHealingEffectOn()) { tScript.stopHealingEffect(); healingSFX.Stop(); } //Debug.Log("stopping effect"); //Debug.Log(tScript.currentHealth); //Debug.Log(tScript.startingHealth); } } } } if (Input.GetButtonUp("Circle") || Input.GetKeyUp(KeyCode.Space)) { heldDuration = 0f; isHealing = false; if (targetTraveller != null) { travellerHealth tScript = targetTraveller.GetComponent <travellerHealth>(); if (tScript.isHealingEffectOn()) { tScript.stopHealingEffect(); healingSFX.Stop(); } } if (travHealingBar.activeInHierarchy) { travHealingBar.SetActive(false); } // moved outside of off claue above (if you move away from trav it'll loop infintely) anim.SetBool("isHealing", false); } if ((Input.GetMouseButtonUp(1) || Input.GetButtonUp("Square")) && stunUnlocked) { if (pController.getResource() >= 20 && monstersInRange.Count >= 1) { setStun(); return; } } if (Input.GetButtonDown("X") || Input.GetMouseButtonDown(0)) { //call stun enemy function if (currentTarget != null && currentTarget.tag == "LampLight") { if (lScript.getCurrentLightType() == 0 && pController.getResource() >= pController.getCurrentResourceNeeded()) { pController.setTargetLight(currentTarget); //set color lScript.setMiniMapPathColor(pController.equippedLight); lScript.turnOnPaths(); //Debug.Log("truning on light"); return; } else if (lScript.getCurrentLightType() > 0) { //Debug.Log("turning off light"); if (!restrictRecover) { pController.setTargetLight(currentTarget); lScript.setMiniMapPathColor(0); lScript.turnOffPaths(); } } } } if (currentTarget && (lScript != null)) { //interactionText.text = "Light"; //popUpText.fontSize = 100; if (lScript.getCurrentLightType() != 0) { //popUpText.fontSize = 110; popUpText.text = "Recover"; popUpTextCount.text = "(+" + (int)lScript.harvestAmount() + ")"; // " + (int) lScript.harvestAmount() } else if (pController.getResource() < pController.getCurrentResourceNeeded()) { //popUpText.fontSize = 70; popUpText.text = "Not Enough!"; if (pController.equippedLight == 1) { popUpTextCount.text = "(-10)"; } else if (pController.equippedLight == 2) { popUpTextCount.text = "(-15)"; } else if (pController.equippedLight == 3) { popUpTextCount.text = "(-15)"; } } else { //popUpText.fontSize = 120; popUpText.text = "Ignite"; if (pController.equippedLight == 1) { popUpTextCount.text = "(-10)"; } else if (pController.equippedLight == 2) { popUpTextCount.text = "(-15)"; } else if (pController.equippedLight == 3) { popUpTextCount.text = "(-15)"; } //(int) pController.getCurrentResourceNeeded() + ")" //Debug.Log("Setting to ignite"); } //popUpText.text = "hello"; //Debug.Log("Could not set text"); return; } else { interactionText.text = ""; return; } }