//Must use this since the animation is so short it cause the nav mesh // to continue moving almost immeditely public void doneAttacking() { GameObject trav = GameObject.FindGameObjectWithTag("Traveller"); travellerHealth travHealth = trav.GetComponent <travellerHealth>(); travHealth.TakeBasicDamage(10); attackSound.enabled = false; if (nav.isStopped) { nav.isStopped = false; } }
private void OnTriggerEnter(Collider other) { if (other.gameObject.CompareTag("Traveller")) { travellerHealth th1 = other.gameObject.GetComponentInChildren <travellerHealth>(); if (th1 == null) { Debug.Log("Could not find travellerHealth script"); } else { th1.TakeStationaryDamage(); } anim.SetTrigger("isDead"); Invoke("playFire", 3f); } }
//Must use this since the animation is so short it cause the nav mesh // to continue moving almost immeditely IEnumerator doneAttacking() { //have to wait for next frame to cheack // yield return new WaitForSeconds(0.4f); //wait until the apex of the animation's swing yield return(new WaitForSeconds(1.0672f)); //Debug.Log("done"); GameObject trav = GameObject.FindGameObjectWithTag("Traveller"); if (trav == null) { Debug.Log("Could not find trav"); } travellerHealth travHealth = trav.GetComponent <travellerHealth>(); if (travHealth == null) { Debug.Log("Could not find health sciprt"); } Animator travAnim = travHealth.getTravellerAnimator(); if (travAnim == null) { Debug.Log("Could not find the traveller animator"); } if (!attackInterrupt && !isStunned) //may have been stunned a few frames before, not interrupted but code raced past, still stunned { travAnim.SetTrigger("isAttacked"); travHealth.TakeBasicDamage(35); attackSound.enabled = false; } if (nav.isStopped) { nav.isStopped = false; } // return; attackInterrupt = false; //yield return null; }
private void Awake() { roamingSound = transform.Find("Audio Source").transform.GetComponent <AudioSource>(); attackSound = transform.Find("Audio Source (1)").transform.GetComponent <AudioSource>(); attackSound.enabled = false; roamingSound.enabled = false; moving = false; traveller = GameObject.FindGameObjectsWithTag("Traveller")[0].transform; tHealth = traveller.GetComponent <travellerHealth>(); tMovement = traveller.GetComponent <travellerMovement>(); nav = GetComponent <NavMeshAgent>(); monsterAnim = GetComponent <Animator>(); col = GetComponent <SphereCollider>(); currentTarget = transform.position; timer = 0f; soundTimer = 0f; upward.Set(0f, 0.2f, 0f); lamps = GameObject.FindGameObjectsWithTag("LampLight"); List <GameObject> validLamps = new List <GameObject>(); foreach (GameObject lamp in setRoaminglamps) { lampQueue.Enqueue(lamp); } bodyAnim = monsterGeo.GetComponent <Animator>(); if (bodyAnim == null) { Debug.Log("Could not find the bodyanim"); } currentAttackCooldown = 0; isStunned = false; isDistracted = false; currentLamp = findCurrentLamp(); //Debug.Log(currentLamp); targetLamp = findCurrentLamp(); attackInterrupt = false; isChaseTrav = false; }
// Use this for initialization void Awake() { endlvl = levelUpMenu.GetComponent <EndLevel>(); currentLight = null; latestLight = null; justVisited = null; targetLight = null; anim = GetComponent <Animator>(); nav = GetComponent <NavMeshAgent>(); travellerHealth = GetComponent <travellerHealth>(); lamps = GameObject.FindGameObjectsWithTag("LampLight"); closeToExit = false; isScared = false; startingPointTransform = new Vector3(startingPoint.transform.position.x, startingPoint.transform.position.y, startingPoint.transform.position.z); movingBack = false; defaultSpeed = nav.speed; fastSpeed = defaultSpeed * 1.5f; }
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; } }
/* * 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; } }