// Start is called before the first frame update void Start() { /*CellDoor = cellDoor1.GetComponent<>(); * CellDoor.SetTrigger("Open Door");*/ //GetComponent<DoorScript>.open doorScriptOnToggle.Open(); }
void Update() { if (hasEntered) { timePassed += Time.deltaTime; } if (timePassed > 10.5f && !amina.HasToldChildrenToHide) { audios[1].Stop(); audios[3].Play(); amina.TellChildrenToHide(); } else if (timePassed > 14.0f && !abdoul.HasAskedWhatsGoingOn) { abdoul.AskWhatsGoingOn(); } else if (timePassed > 15.5f && !amina.HasToldChildrenTheSoldiersAreBack) { amina.TellChildrenTheSoldiersAreBack(); closetDoor.Close(); mainDoor.Open(); amina.FaceSoldiersAndSlideBack(); audios[2].Play(); soldier1.EnterSchool(); soldier2.EnterSchool(); } }
private void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.tag == "Bullet" && !isJumping && !isInvinsible) { health--; isInvinsible = true; } else if (other.gameObject.tag == "Jam" && !isJumping) { Heal(0.3); } else if (other.gameObject.tag == "Door") { DoorScript doorScript = other.transform.parent.gameObject.GetComponent <DoorScript>(); bool hasKey = false; if (doorScript != null) { for (int i = 0; i < foundKeys.Count; i++) { KeyScript keyScript = foundKeys[i].GetComponent <KeyScript>(); if (doorScript.keyColorToOpen == keyScript.color) { hasKey = true; Destroy(keyScript.gameObject); } } if (hasKey) { doorScript.Open(); } else { isStuck = true; } } } if (health == 3) { playerSprite.GetComponent <SpriteRenderer>().sprite = Damage3; } if (health == 2) { playerSprite.GetComponent <SpriteRenderer>().sprite = Damage2; } if (health == 1) { playerSprite.GetComponent <SpriteRenderer>().sprite = Damage1; } if (health == 0) { SceneManager.LoadScene(4, LoadSceneMode.Single); } }
void OnTriggerEnter(Collider collider) { if (collider.tag == "DoorTrigger") { DoorScript door = FindDoor(collider.gameObject); if (door == null) { return; } door.Open(); if (door.TeleporterDestination != null) { transform.position = door.TeleporterDestination.transform.position; } } }
// Update is called once per frame void Update() { if (!HUDScript.isPaused && !HUDScript.isGameOver) { //Rotation float rotateX = Input.GetAxis("Mouse X") * 2.0f; //increase mouse sensitivity w/ 2.0 //float rotateY = Input.GetAxis ("Mouse Y"); Vector3 rotate = new Vector3(0, rotateX, 0); //cc.center.x, 0);//rotateX, 0); transform.Rotate(rotate); /* * //raycast detection (for sanity) * RaycastHit hit; * * Vector3 p1 = transform.position + cc.center; * float distanceToObstacle = 0; * * // Cast a sphere wrapping character controller 5 meters forward * // to see if it is about to hit anything. * if (Physics.SphereCast(p1, cc.height / 2, transform.forward, out hit, 1.5f)) { * //Debug.DrawRay(transform.position, (cc.transform.position - transform.position), Color.green); // show path of SphereCast * //Debug.Log("rayHit.collider.tag " + hit.collider.tag); // print collider info * * if (hit.collider.tag == "Enemy" ) { * //lower sanity * distanceToObstacle = hit.distance; * hud.DecSanity(0.4f); * } * } * if (Physics.SphereCast(p1, cc.height / 2, -transform.forward, out hit, 1.5f)) * { * //Debug.DrawRay(transform.position, (cc.transform.position - transform.position), Color.green); // show path of SphereCast * //Debug.Log("rayHit.collider.tag " + hit.collider.tag); // print collider info * * if (hit.collider.tag == "Enemy") * { * //lower sanity * distanceToObstacle = hit.distance; * hud.DecSanity(0.4f); * } * } * } * * //end of raycast detection (for sanity) */ //movement //can multiply these to make them go faster float forwardSpeed = Input.GetAxis("Vertical") * 2.0f; float sideSpeed = Input.GetAxis("Horizontal") * 2.0f; //x(left-right), y(up-down), z(forward-back) verticalVelocity += Physics.gravity.y * Time.deltaTime; //increase speed down over time if (Input.GetButtonDown("Crouch") && cc.isGrounded == true) { cc.height = 0f; //cc.radius = 0.1f; } else if (Input.GetButtonUp("Crouch") && cc.isGrounded == true) { Vector3 temp = new Vector3(transform.position.x, transform.position.y + 0.8f, transform.position.z); Ray crouchRay = new Ray(temp, transform.up); RaycastHit crouchHit; if (Physics.Raycast(crouchRay, out crouchHit, 2.0f)) { //Debug.Log ("Hit"); Debug.DrawLine(crouchRay.origin, crouchHit.point, Color.green); cc.height = 0f; } else { cc.height = 2.5f; } } // // unCrouch(); //} if (RotateBook) { book.transform.Rotate(0, 0, 35.0f * (Time.deltaTime / 2)); amountRot += 35.0f * (Time.deltaTime / 2); if (amountRot > 35.0f) { RotateBook = false; moveBookcase = true; } } if (moveBookcase && Bookcase.transform.localPosition.x < 22.6f) { bcs.Play(); Bookcase.transform.Translate(Vector3.back * 1.0f * Time.deltaTime); book.transform.Translate(Vector3.back * 1.0f * Time.deltaTime); Skulls.transform.Translate(Vector3.down * 4.0f * Time.deltaTime); //back(y-), forward(y++), right(x++), left(x--), up?? //bcs.Play(); } if (Skulls.transform.position.z < 7.0f && Skulls.transform.position.z > -17.0f) { Skulls.transform.Translate(Vector3.down * 5.0f * Time.deltaTime); } if (Input.GetButtonDown("Open")) { if ((Vector3.Distance(transform.position, book.transform.position) < 5)) { RotateBook = true; } } if (Input.GetButtonDown("Open")) { if ((Vector3.Distance(transform.position, Flashlight.transform.position) < 5)) { HasFlashlight = true; Flashlight.transform.localPosition = new Vector3(-100, -100, -100); //GUI.Label (Rect(10, 10, 100, 20), "Press M to work the flashlight"); } } } if (Input.GetButtonDown("Light") && HasFlashlight == true) { click.Play(); if (playerFlashlight.intensity == 0) { playerFlashlight.intensity = 7; } else { playerFlashlight.intensity = 0; } } if (Input.GetButtonDown("Jump") && cc.isGrounded == true) //isgrounded means the character is on the ground { verticalVelocity = jumpSpeed; } else if (Input.GetKey(KeyCode.Escape) && !HUDScript.isPaused && !HUDScript.isGameOver) { hud.PauseGame(); } else if (Input.GetKey("o")) { //hud.DecSanity(1); } else if (Input.GetKey("p")) { //hud.IncSanity(1); } else if (Input.GetButtonDown("Open")) { //press e if object is tagged as door get the object and then call OpenClose function in DoorScript Vector3 fwd = transform.TransformDirection(Vector3.forward); RaycastHit doorhit; if (Physics.Raycast(transform.position, fwd, out doorhit)) { if ((transform.position - doorhit.transform.position).magnitude <= 3.0f) { if (doorhit.collider.tag == "Door") { DoorScript dr = doorhit.transform.gameObject.GetComponent <DoorScript> (); if (dr.isopen()) { dr.Close(); } else { dr.Open(); } } else if (doorhit.collider.tag == "FrontDoor" && HasFlashlight) { DoorScript dr = doorhit.transform.gameObject.GetComponent <DoorScript> (); dr.Open(); hud.WonGame(); } } } } speed = new Vector3((sideSpeed * 2), verticalVelocity, (forwardSpeed * 2)); //editing speed to match camera direction speed = transform.rotation * speed; //cc.SimpleMove (speed); //cant use simple move if we want any Y components (jumping/falling, etc) //simple move has gravity included if (!HUDScript.isPaused && !HUDScript.isGameOver) { cc.Move(speed * Time.deltaTime); } } /* * void unCrouch() * { * cc.height = 2 ; * crouching = false; * } * */ }
private void OnTriggerStay2D(Collider2D collision) { if (collision.gameObject.tag == "PickUpUnique") { if (Input.GetKey(KeyCode.E)) { if (!CharacterHas(collision)) { PickUp(collision); } else { dialogSystem.Show("UniqueTwicePickUp.txt"); } } } if (collision.gameObject.tag == "Door") { if (Input.GetKey(KeyCode.E)) { DoorScript door = collision.gameObject.GetComponent <DoorScript>(); if (door.isAccessible) { door.Open(); if (collision.name == "FlatDoor") { saveManager.Save(); SceneManager.LoadScene("02-Secondhand"); } if (collision.name == "FlatWardrobe") { collision.transform.Find("QuestReceiver").GetComponent <QuestReceiver>().FinishQuest(); door.isAccessible = false; } } else { if (collision.name == "FlatDoor") { dialogSystem.Show("01EarlyDoor.txt"); } if (collision.name == "FlatDoor") { dialogSystem.Show("01EarlyDoor.txt"); } // message.Show("Кажется, мне туда ещё рано..."); } } } if (collision.gameObject.tag == "PickUp") { if (Input.GetKey(KeyCode.E)) { PickUp(collision); } } if (collision.gameObject.tag == "PickUpSpell") { if (Input.GetKey(KeyCode.E)) { PickUpSpell(collision); } } if (collision.gameObject.name == "MagicClothes") { if (Input.GetKey(KeyCode.E)) { collision.transform.Find("QuestReceiver").GetComponent <QuestReceiver>().FinishQuest(); } } if (collision.gameObject.tag == "ExitBlocker") { var blocker = collision.GetComponent <ExitBlockerScript>(); if (blocker.isOpened) { if (SceneManager.GetActiveScene().name == "03-Castle") { } if (SceneManager.GetActiveScene().name == "04-Village") { saveManager.Save(); SceneManager.LoadScene("05-Forest"); } if (SceneManager.GetActiveScene().name == "05-Forest") { saveManager.Save(); SceneManager.LoadScene("06-Town"); } if (SceneManager.GetActiveScene().name == "06-Town") { saveManager.Save(); SceneManager.LoadScene("07-Castle"); } } else { // Debug.Log((dialogSystem == null).ToString()+ "d" + this.gameObject.name); GameObject.Find("DialogSystem").GetComponent <DialogSystem>().Show("WrongWay.txt"); } } if (collision.gameObject.tag == "Talkable") { if (Input.GetKey(KeyCode.E)) { if (collision.name == "granny") { var quest = questSystem.GetByTag("GrannyQuest"); if (quest == null || !quest.IsFinished) { dialogSystem.Show("03VillageGranny.txt"); questSystem.Add(new CatFishScripts.Quest("GrannyQuest", null, "Собрать цветы для зелья")); } else { dialogSystem.Show("03VillageGrannyCompleted.txt"); } } if (collision.name == "OldMan") { var quest = questSystem.GetByTag("BullQuest"); var quest2 = questSystem.GetByTag("OldManQuest"); collision.transform.Find("???QuestReceiver").GetComponent <QuestReceiver>().FinishQuest(); if (quest == null || quest2 == null) { dialogSystem.Show("03VillageOldMan.txt"); questSystem.Add(new CatFishScripts.Quest("BullQuest", null, "Успокоить быка на поле")); questSystem.Add(new CatFishScripts.Quest("OldManQuest", null, "Помочь людям в деревне")); } else { if (questSystem.GetByTag("BullKilledQuest") == null || questSystem.GetByTag("SaintWaterTell") == null || !questSystem.GetByTag("SaintWaterTell").IsFinished || questSystem.GetByTag("GrannyQuest") == null || !questSystem.GetByTag("GrannyQuest").IsFinished) { dialogSystem.Show("03VillageOldManCompleting.txt"); return; } collision.transform.Find("MainQuestReceiver").GetComponent <QuestReceiver>().FinishQuest(); collision.transform.Find("BullKilledQuestReceiver").GetComponent <QuestReceiver>().FinishQuest(); dialogSystem.Show("03VillageOldManCompleted.txt"); } } if (collision.name == "SaintBrother") { var quest = questSystem.GetByTag("SaintWater"); if (quest == null) { dialogSystem.Show("03SaintBrotherStart.txt"); questSystem.Add(new CatFishScripts.Quest("SaintWater", null, "Освятите колодец")); } else if (!quest.IsFinished) { dialogSystem.Show("03SaintBrotherCompleting.txt"); } else { collision.transform.Find("QuestReceiver").GetComponent <QuestReceiver>().FinishQuest(); dialogSystem.Show("03SaintBrotherCompleted.txt"); } } if (collision.name == "oldboy") { var quest = questSystem.GetByTag("Mushrooms"); if (quest == null) { dialogSystem.Show("04OldBoyStart.txt"); questSystem.Add(new CatFishScripts.Quest("Mushrooms", null, "Соберите съедобные грибы")); } else { //collision.transform.Find("QuestReceiver").GetComponent<QuestReceiver>().FinishQuest(); dialogSystem.Show("04OldBoyFinish.txt"); } } if (collision.name == "goblin") { dialogSystem.Show("04Goblin.txt"); } if (collision.name == "priest") { dialogSystem.Show("03Priest.txt"); } if (collision.name == "gnome" || collision.name == "gnome2") { dialogSystem.Show("05Gnomes.txt"); } if (collision.name == "warrior") { dialogSystem.Show("05Security.txt"); } if (collision.name == "warrior") { dialogSystem.Show("05Security.txt"); } if (collision.name == "Mag") { dialogSystem.Show("06Mag.txt"); } if (collision.name == "elf") { var quest = questSystem.GetByTag("ElfQuest"); if (quest == null) { dialogSystem.Show("05ElfStart.txt"); questSystem.Add(new CatFishScripts.Quest("ElfQuest", null, "Помогите эльфу")); } else if (GameObject.Find("goblin").GetComponent <UnityCharacter>().Character.Condition == CatFishScripts.Characters.Character.ConditionType.dead && collision.GetComponent <UnityCharacter>().Character.Inventory.Artifacts.Count == 1) { collision.transform.Find("QuestReceiver").GetComponent <QuestReceiver>().FinishQuest(); dialogSystem.Show("05ElfEnd.txt"); } else if (quest.IsFinished) { dialogSystem.Show("05ElfFullEnd.txt"); } } } } }