public void monsterLampLit(GameObject litLamp) { Debug.Log("MonsterLampLit"); GameObject lamp; if (targetLamp == null) { lamp = currentLamp; } else { lamp = targetLamp; } lightSourceController lController = lamp.GetComponentInParent <lightSourceController>(); if (lController == null) { Debug.Log("Could not find lightsourcontroller"); } else { GameObject[] adjacentLamps = lController.getAdjacentSources(); foreach (GameObject adjacentlamp in adjacentLamps) { if (litLamp == adjacentlamp) { targetLamp = litLamp; currentTarget = litLamp.transform.position; nav.SetDestination(currentTarget); movingToLamp = true; } } } }
/* * 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 createLightCountDowns() { foreach (GameObject m in GameObject.FindGameObjectsWithTag("LampLight")) { lightSourceController lController = m.GetComponent <lightSourceController>(); if (lController == null) { Debug.Log("Could not find lController"); } else { GameObject countDownPopUp = Instantiate(lightCountdown, transform.position, Quaternion.identity); // countDownPopUp.transform.parent = worldCanvas.transform; countDownPopUp.transform.SetParent(worldCanvas.transform); countDownPopUp.SetActive(false); Vector3 popUpLocation = m.transform.position; popUpLocation.y = popUpLocation.y + textVerticalOffset; lController.countDown = countDownPopUp; lController.countDown.GetComponent <WorldSpaceObjectController>().updateWorldObjectTransform(popUpLocation); } } }
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 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; } }
void controlLureImage() { //check if light is in traveller radius GameObject trav = GameObject.FindGameObjectWithTag("Traveller"); if (trav == null) { Debug.Log("Could not find the traveller"); } travellerScript tScript = trav.GetComponent <travellerScript>(); if (tScript == null) { Debug.Log("could not find tScript"); } //get the current lamp that the traveller is at // get its adjacent lamps from light controller // check against our current target //if it is //lureImage.sprite = travellerLureIcon; //go through all monster tagged objects //for each grab script and get the current lamp foreach (GameObject g in GameObject.FindGameObjectsWithTag("Monster")) { EnemyMovement eMovement = g.GetComponent <EnemyMovement>(); if (eMovement == null) { Debug.Log("Could not find monster movement script"); } GameObject lamp = eMovement.findCurrentLamp(); if (lamp != null) { lightSourceController lController = lamp.GetComponent <lightSourceController>(); if (lController == null) { Debug.Log("Could not find light source controller"); } //if (lController.getAdjacentSources().) if (checkAdjacent(lController.getAdjacentSources())) { //check if monster is in monster radius //lureImage.enabled = true; //lureImage.sprite = monsterLureIcon; } } } }
public void monsterLampLit(GameObject litLamp) { float distance = Mathf.Infinity; GameObject newCurrentLamp = null; foreach (GameObject newlamp in lamps) //this part is also not quite working { if (Vector3.Distance(transform.position, newlamp.transform.position) < distance) // edge case, does not take into account lit lamp { distance = Vector3.Distance(transform.position, newlamp.transform.position); newCurrentLamp = newlamp; } } Debug.Log("MonsterLampLit"); if (newCurrentLamp == litLamp) { monsterAnim.SetTrigger("nearbyLitLamp"); Debug.Log("inhere1"); targetLamp = litLamp; currentTarget = litLamp.transform.position; nav.SetDestination(currentTarget); movingToLamp = true; if (!isBaby) { isDistracted = true; } } lightSourceController lController = newCurrentLamp.GetComponentInParent <lightSourceController>(); if (lController == null) { Debug.Log("Could not find lightsourcontroller"); } else { GameObject[] adjacentLamps = lController.getAdjacentSources(); foreach (GameObject adjacentlamp in adjacentLamps) { if (litLamp == adjacentlamp) { monsterAnim.SetTrigger("nearbyLitLamp"); Debug.Log("inhere2"); targetLamp = litLamp; currentTarget = litLamp.transform.position; nav.SetDestination(currentTarget); movingToLamp = true; if (!isBaby) { isDistracted = 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); }
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); } }
public void setTravelIcon(GameObject lamp) { GameObject trav = GameObject.FindGameObjectWithTag("Traveller"); if (trav == null) { Debug.Log("Could not find traveller"); } travellerMovement tScript = trav.GetComponent <travellerMovement>(); if (tScript == null) { Debug.Log("could not find travellerscript"); } if (tScript.currentLight == null) { if (checkAdjacent(tScript.startAdjacent, lamp)) { lureImage.sprite = travellerLureIcon; lureImage.enabled = true; } else { lureImage.enabled = false; } } else { GameObject travLamp = tScript.currentLight; lightSourceController lController = travLamp.GetComponent <lightSourceController>(); if (lController == null) { Debug.Log("Could not find the lights controller script"); } if (checkAdjacent(lController.adjacentSources, lamp)) { lureImage.sprite = travellerLureIcon; lureImage.enabled = true; } else { lureImage.enabled = false; } } }
bool isLit(GameObject lamp) { lightSourceController lScript = lamp.GetComponentInParent <lightSourceController>(); if (lScript != null) { int lightType = lamp.GetComponentInParent <lightSourceController>().getCurrentLightType(); return(lightType == 1 || lightType == 3); } else { return(false); } }
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; } } } }
void OnTriggerExit(Collider other) { if (other.tag == "Traveller" && other.gameObject == targetTraveller) { //currentTarget = null; travellerHealth tScript = other.gameObject.GetComponent <travellerHealth>(); tScript.stopHealingEffect(); interactionPopUp3.SetActive(false); travHealingBar.SetActive(false); targetTraveller = null; healingSFX.Stop(); //interactionText.text = ""; return; } if (other.tag == "LampLight" && other.gameObject == currentTarget) { if (lScript != null) { if (lScript.getCurrentLightType() == 0) { //lScript.setMiniMapPathColor(0); lScript.turnOffPaths(); //Debug.Log("turning off)"); } lScript.turnOffWorldPaths(); lScript.switcherScript.setDefault(); } interactionPopUp.SetActive(false); currentTarget = null; lScript = null; return; } }
// Use this for initialization void Start() { lightObject = this.transform.parent.gameObject; lightScript = lightObject.GetComponent <lightSourceController>(); my_renderer = GetComponent <MeshRenderer>(); if (my_renderer != null) { default_mat = my_renderer.material; } //currentDefault // currentLit = materials = GetComponent <Renderer>().materials; meshRenderer = GetComponent <MeshRenderer>(); if (meshRenderer == null) { Debug.Log("Could nto find msh renderer"); } // materials[1].SetFloat("_FirstOutlineWidth", 0); currentDefault = default_mat; currentLit = lit_mat; //my_renderer.ma //Debug.Log(materials.Length); /* * if (materials.Length <2) * { * Material[] newMaterials = new Material[2]; * newMaterials[0] = default_mat; * newMaterials[1] = litOutline; * GetComponent<Renderer>().materials = newMaterials; * materials = GetComponent<Renderer>().materials; * setDefault(); * } */ }
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; } } } }
/* * 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); }
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); * } */ }
/* * void OnTriggerEnter(Collider other) * { * if (other.gameObject.CompareTag("LampLight") && lightReady) * { * count = count + 1; * SetCountText(); * cCollider = other.GetComponentInParent<CapsuleCollider>(); * lampLight = other.gameObject.GetComponentInChildren<Light>(); * Material bulb = other.GetComponentInChildren<Renderer>().material; * //Behaviour halo =(Behaviour)other.GetComponent ("Halo"); * * //.Log(bulb.name); * if (bulb == null) * Debug.Log("HHH"); * if (lampLight.intensity > 0) * { * lampLight.intensity = 0; * cCollider.enabled = false; * audioSource.clip = offSoundEffect; * audioSource.Play(); * tScript.setTarget(other.transform.parent.transform, lampLight.intensity); * * bulb.DisableKeyword("_EMISSION"); * // Debug.Log("adding back scost"); * //addResource(tempLightCost); * * //halo.enabled = false; * * } * else{ * //setLightColor(lampLight, equippedLight); * if (lightResource >=tempLightCost){ * * setChildLight(other.GetComponentsInChildren<Light>()); * * lampLight.intensity = 3; * cCollider.enabled = true; * audioSource.clip = onSoundEffect; * audioSource.Play(); * tScript.setTarget(other.transform.parent.transform, lampLight.intensity); * bulb.EnableKeyword("_EMISSION"); * setMaterialColor(bulb, equippedLight); * * // halo.enabled = true; * * //addResource(-tempLightCost); * subtractResource(); * } * //halo.enabled = true; * } * } * * * } * */ public void setTargetLight(GameObject lightSource) { //Debug.Log("called set light"); if (lightSource.CompareTag("LampLight")) { // Debug.Log(lightSource.transform.position); count = count + 1; SetCountText(); // cCollider = lightSource.GetComponentInParent<CapsuleCollider>(); lampLight = lightSource.gameObject.GetComponentInChildren <Light>(); Material bulb = lightSource.GetComponentInChildren <Renderer>().material; //Behaviour halo =(Behaviour)other.GetComponent ("Halo"); //.Log(bulb.name); if (bulb == null) { Debug.Log("HHH"); } if (lampLight.intensity > 0) { lampLight.intensity = 0; // cCollider.enabled = false; audioSource.clip = offSoundEffect; audioSource.Play(); if (equippedLight == 1 || equippedLight == 2) { tScript.setTarget(lightSource.transform, lampLight.intensity); } bulb.DisableKeyword("_EMISSION"); //addResource(tempLightCost); //halo.enabled = false; lightSourceController lController = lightSource.GetComponentInParent <lightSourceController>(); if (lController != null) { lController.setCurrentLightType(0); } } else { //setLightColor(lampLight, equippedLight); if (lightResource >= tempLightCost) { setChildLight(lightSource.GetComponentsInChildren <Light>()); lampLight.intensity = lightValueOn; // cCollider.enabled = true; audioSource.clip = onSoundEffect; audioSource.Play(); if (equippedLight == 1 || equippedLight == 2) { tScript.setTarget(lightSource.transform, lampLight.intensity); } bulb.EnableKeyword("_EMISSION"); setMaterialColor(bulb, equippedLight); // halo.enabled = true; //addResource(-tempLightCost); subtractResource(); lightSourceController lController = lightSource.GetComponentInParent <lightSourceController>(); if (lController != null) { lController.setCurrentLightType(equippedLight); } } //halo.enabled = true; } } }
// Use this for initialization void Start() { LSC = light.GetComponent <lightSourceController>(); obj = GetComponent <Projector>(); }
public void setTargetLight(GameObject lightSource) { //Debug.Log("called set light"); if (lightSource.CompareTag("LampLight")) { count = count + 1; SetCountText(); lampLight = lightSource.gameObject.GetComponentInChildren <Light>(); // Material bulb = lightSource.GetComponentInChildren<Renderer>().material; // if (bulb == null) // Debug.Log("HHH"); if (lampLight.intensity > 0) { lampLight.intensity = 0; audioSource.clip = offSoundEffect; audioSource.Play(); if (equippedLight == 1 || equippedLight == 2) { tMovement.findLatest(lightSource); } //bulb.DisableKeyword("_EMISSION"); lightSourceController lController = lightSource.GetComponentInParent <lightSourceController>(); if (lController != null) { lController.setCurrentLightType(0); } } else { setChildLight(lightSource.GetComponentsInChildren <Light>()); lampLight.intensity = lightValueOn; audioSource.clip = onSoundEffect; audioSource.Play(); if (equippedLight == 1 || equippedLight == 2) { tMovement.findLatest(lightSource); } subtractResource(); lightSourceController lController = lightSource.GetComponentInParent <lightSourceController>(); if (lController != null) { lController.setCurrentLightType(equippedLight); } if (equippedLight == 1 || equippedLight == 3) { GameObject[] monsters = GameObject.FindGameObjectsWithTag("Monster"); foreach (GameObject g in monsters) { EnemyMovement eScript = g.GetComponent <EnemyMovement>(); if (eScript == null) { Debug.Log("Could not find script for monster"); } else { eScript.monsterLampLit(lightSource); } } } } } }
void Update() { if (bodyAnim.GetCurrentAnimatorStateInfo(0).IsName("Attacking")) { //for now do nothing while animation completes //channge nothing, it can go back to doing what it does after // var rotation = Quaternion.LookRotation(traveller.position); var rotation = Quaternion.LookRotation(traveller.position - transform.position); transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * 10f); nav.SetDestination(transform.position); return; } /* * else { //once animation is done make sure we can move again * if (nav.isStopped) * nav.isStopped = false; * } */ //for testing purposes //if (Input.GetKeyDown(KeyCode.M)) //{ // startAttack(); // } if (currentAttackCooldown != 0) { currentAttackCooldown = Mathf.Clamp(currentAttackCooldown -= Time.deltaTime, 0f, attackCooldownValue); } //monster sounds; possibly temporary, depending if we use 3D audio controller //The attackSound is almost definitely temporary, assuming we will someday have //and attack state soundTimer += Time.deltaTime; float distanceFromTraveler = Vector3.Distance(transform.position, traveller.transform.position); if (distanceFromTraveler < 1 && !isDistracted) { if (startAttack()) { attackSound.enabled = true; attackSound.volume = 0.5f; if (!attackSound.isPlaying) { if (roamingSound.isPlaying) { roamingSound.Pause(); } attackSound.Play(); } } } if (distanceFromTraveler < 3 && !tHealth.isDead && !tMovement.closeToExit)// && distanceFromTraveler > 1) { if (soundTimer < 2) { roamingSound.enabled = true; roamingSound.volume = (1 / distanceFromTraveler) / 2; if (!roamingSound.isPlaying && !attackSound.isPlaying) { roamingSound.Play(); } } else { roamingSound.Stop(); roamingSound.enabled = false; } } else { if (!roamingSound.isPlaying && roamingSound.enabled) { roamingSound.Play(); } roamingSound.volume = 0; } if (soundTimer > 4) { roamingSound.volume = 0; soundTimer = 0f; } //end of monster sound control if (monsterAnim.GetCurrentAnimatorStateInfo(0).IsName("Stunned")) { if (isChaseTrav) { isChaseTrav = false; } nav.SetDestination(transform.position); nav.velocity = Vector3.zero; nav.isStopped = true; //Monster sounds roamingSound.enabled = false; attackSound.enabled = false; timer += Time.deltaTime; int countDown = 9 - (int)timer; popUp2.GetComponent <WorldSpaceObjectController>().setPopUpText(countDown.ToString()); if (timer > 9) { popUp2.SetActive(false); monsterAnim.SetTrigger("recovered"); //Monster sounds roamingSound.enabled = true; timer = 0f; movingToLamp = false; isStunned = false; } return; } else if (monsterAnim.GetCurrentAnimatorStateInfo(0).IsName("Chase")) { currentTarget = traveller.position; nav.SetDestination(currentTarget); nav.isStopped = false; isChaseTrav = true; if (Vector3.Distance(roamCenterPoint, traveller.position) >= maxRoamDistance) { monsterAnim.SetTrigger("travellerLost"); //monster sounds roamingSound.enabled = true; attackSound.enabled = false; movingToLamp = false; isChaseTrav = false; } if (distanceFromTraveler < 1) { isChaseTrav = false; nav.isStopped = true; } } else if (monsterAnim.GetCurrentAnimatorStateInfo(0).IsName("Alerted")) { //Debug.Log("Alerted"); isChaseTrav = false; isDistracted = false; RaycastHit hit; if (Physics.Raycast(transform.position + upward, direction.normalized, out hit, Mathf.Infinity)) { if (hit.collider.gameObject.transform == traveller) { monsterAnim.SetTrigger("travellerSpotted"); } else { monsterAnim.SetTrigger("isLooking"); } } } else { isChaseTrav = false; if (!movingToLamp) { // not currently moving, find new place to move to nextLamp(lampQueue); } else if (Vector3.Distance(transform.position, currentTarget) < lampDistance) { movingToLamp = false; isDistracted = false; nav.SetDestination(transform.position); nav.velocity = Vector3.zero; nav.isStopped = true; currentLamp = findCurrentLamp(); } else { if (!isLit(targetLamp)) { float timeRemaining = 0f; int lampPriority = 0; lightSourceController lScript = targetLamp.GetComponentInParent <lightSourceController>(); if (lScript != null) { GameObject[] adjLamps = lScript.getAdjacentSources(); foreach (GameObject lamp in adjLamps) { if (isLit(lamp)) { if ((timeRemaining < getTimeRemaining(lamp)) && (lampPriority <= getLampPriority(lamp))) { targetLamp = lamp; timeRemaining = getTimeRemaining(lamp); movingToLamp = true; bodyAnim.SetBool("isMoving", true); } } } } } currentTarget = targetLamp.transform.position; nav.SetDestination(currentTarget); nav.isStopped = false; } } //Debug.Log(isChaseTrav); if (((Vector3.Distance(transform.position, currentTarget) < lampDistance) && !isChaseTrav) || isStunned) { bodyAnim.SetBool("isMoving", false); } else { bodyAnim.SetBool("isMoving", true); } /* * if (!isStunned) * { * if (movingToLamp != bodyAnim.GetBool("isMoving")) * { * //Debug.Log("called switch"); * bodyAnim.SetBool("isMoving", movingToLamp); * } * } */ }
public void monsterLampLit(GameObject litLamp) { if (isStunned) { return; } if (monsterAnim.GetCurrentAnimatorStateInfo(0).IsName("Chase") && !((getLampPriority(litLamp) == 3))) { currentTarget = traveller.position; nav.SetDestination(currentTarget); nav.isStopped = false; isChaseTrav = true; return; } float distance = Mathf.Infinity; GameObject newCurrentLamp = null; foreach (GameObject newlamp in lamps) //this part is also not quite working { if (Vector3.Distance(transform.position, newlamp.transform.position) < distance) // edge case, does not take into account lit lamp { distance = Vector3.Distance(transform.position, newlamp.transform.position); newCurrentLamp = newlamp; } } // Debug.Log("MonsterLampLit"); if ((newCurrentLamp == litLamp) && (getLampPriority(targetLamp) <= getLampPriority(litLamp))) { monsterAnim.SetTrigger("nearbyLitLamp"); //Debug.Log("inhere1"); targetLamp = litLamp; currentTarget = litLamp.transform.position; nav.SetDestination(currentTarget); nav.isStopped = false; movingToLamp = true; bodyAnim.SetBool("isMoving", true); if (!isBaby) { isDistracted = true; } } lightSourceController lController = newCurrentLamp.GetComponentInParent <lightSourceController>(); if (lController == null) { Debug.Log("Could not find lightsourcontroller"); } else { GameObject[] adjacentLamps = lController.getAdjacentSources(); foreach (GameObject adjacentlamp in adjacentLamps) { if ((litLamp == adjacentlamp) && (getLampPriority(targetLamp) <= getLampPriority(litLamp))) { Debug.Log("target:" + getLampPriority(targetLamp) + " litlamp:" + getLampPriority(litLamp)); monsterAnim.SetTrigger("nearbyLitLamp"); // Debug.Log("inhere2"); targetLamp = litLamp; currentTarget = litLamp.transform.position; nav.SetDestination(currentTarget); nav.isStopped = false; movingToLamp = true; bodyAnim.SetBool("isMoving", true); if (!isBaby) { isDistracted = true; } } } } }
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); * } * * * * * } * */ }