private void Update() { if (transform.position.y < -100) { gm.LoseGame(); } if (Input.GetAxis("Vertical") != 0) { curspeed += acceleration; if (curspeed > speed) { curspeed = speed; } } else if (curspeed != 0) { curspeed -= acceleration; } float translationx = Input.GetAxis("Vertical") * curspeed; float rotation = Input.GetAxis("Horizontal") * rotationSpeed; float rotationv = Input.GetAxis("Camera Vertical") * rotationSpeed; float rotationh = Input.GetAxis("Camera Horizontal") * rotationSpeed; axel.Rotate(0, 0, -0.1f * translationx); translationx *= Time.deltaTime; rotationv *= Time.deltaTime; rotationh *= Time.deltaTime; rotation *= Time.deltaTime; if (currHorRot != 0 && translationx != 0) { transform.Rotate(0, currHorRot / 5, 0); cameraAnchorH.transform.Rotate(0, -currHorRot / 5, 0.0f); currHorRot -= currHorRot / 5; } transform.Rotate(0, rotation, 0); Vector3 forward_direction = transform.TransformDirection(Vector3.left); Vector3 forward_velocity = new Vector3(28 * forward_direction.z * translationx, rb.velocity.y, -28 * forward_direction.x * translationx); rb.velocity = forward_velocity; if (stationary && translationx != 0) { if (speed == 80) { animator.SetTrigger("startedSprinting"); } else { animator.SetTrigger("startedWalking"); } } stationary = translationx == 0; currVerRot = 0; if (rotationh != 0 && (currHorRot < 90 && currHorRot > -90)) { currHorRot += rotationh; cameraAnchorH.transform.Rotate(0, rotationh, 0.0f); cameraSetBack = 2.5f; } else if (rotationh == 0 && (currHorRot > 0.01 || currHorRot < -0.01) && cameraSetBack < 0) { cameraAnchorH.transform.Rotate(0, -currHorRot / 10, 0.0f); currHorRot -= currHorRot / 10; } else if (rotationh == 0 && currHorRot < 0.1 && currHorRot > -0.1 && cameraSetBack < 0) { cameraAnchorH.transform.Rotate(0, -currHorRot, 0.0f); currHorRot = 0; } else if (rotationh == 0) { cameraSetBack -= Time.deltaTime; } var hitColliders = Physics.OverlapSphere(transform.position, 4); var hitColliderss = Physics.OverlapSphere(transform.position + new Vector3(0, 5, 0), 8); bool teleHere = false; bool engineHere = false; if (Input.GetButtonDown("Fire1") && jump == true && paused == false) { rb.velocity += new Vector3(0, 40, 0); tilePickupAudio.PlayOneShot(mm.jump); animator.SetTrigger("startedJumping"); jump = false; } if (Input.GetButtonDown("Fire2")) { Vector3 forward = transform.TransformDirection(Vector3.forward); if (engineHere == false) { forward = new Vector3(-12 * forward.x, 5, -12 * forward.z); powerups.Createbox(transform.position + forward, color); } else { } } if (Input.GetButtonDown("Fire3")) { powerups.GetEnginePower(transform.position); } for (int i = 0; i < hitColliderss.Length; i++) { if (hitColliderss[i].tag == "tele" && powerups.tele_num > 0) { teleHere = true; break; } for (i = 0; i < hitColliderss.Length; i++) { if (hitColliders[i].tag == ("engine")) { engineHere = true; break; } ; } } if (Input.GetButtonDown("Fire3") && (color == Color.blue) && teleHere) { for (int i = 0; i < hitColliderss.Length; i++) { if (hitColliderss[i].tag == "tele" && powerups.tele_num > 0) { Destroy(hitColliderss[i].gameObject); powerups.tele_num--; //if (powerups.yellowbox1 != null && powerups.tele_num == 1) //{ // Debug.Log("get1"); // powerups.yellowbox2 = null; //} //else if (powerups.yellowbox2 != null && powerups.tele_num == 1) //{ // Debug.Log("get2"); // powerups.yellowbox1 = powerups.yellowbox2; // powerups.yellowbox2 = null; //} } } } else if (Input.GetButtonDown("Fire3") && carry == false) { for (int i = 0; i < hitColliders.Length; i++) { if (hitColliders[i].tag == "move") { carryThing = (hitColliders[i].gameObject); carry = true; dropCarryTimer = 0.5f; tilePickupAudio.PlayOneShot(mm.pickUpBox); } //tilePickupAudio.PlayOneShot(mm.blastAudio); } } else if (Input.GetButtonDown("Fire2") && carry) { if (hitColliders.Length < 5) { if (dropCarryTimer <= 0) { Vector3 forward = transform.TransformDirection(Vector3.left); forward = new Vector3(3 * forward.z, 2, -3 * forward.x); carryThing.transform.position = transform.position + forward; carry = false; tilePickupAudio.PlayOneShot(mm.putDownBox); } } else if (msgDisp) { msgDispTimer = 2; string msg = "Cannot place box here."; msgDisp.text = msg; } } if (carry && carryThing) { carryThing.transform.position = transform.position + new Vector3(0, 15, 0); } if (Input.GetKey("r")) { gm.RestartLevel(); } if (Input.GetButtonDown("Jump") && (color == Color.red)) { for (int i = 0; i < hitColliders.Length; i++) { if (hitColliders[i].tag == "blast") { Destroy(hitColliders[i].gameObject); } //tilePickupAudio.PlayOneShot(mm.blastAudio); } } if (Input.GetButton("Jump") && color == Color.green) { tilePickupAudio.PlayOneShot(mm.runfasterAudio); speed = 80; } else { speed = 40; } if (Input.GetButtonDown("Jump") && (color == Color.blue) && powerups.tele_num < 2) { Vector3 forward = transform.TransformDirection(Vector3.left); forward = new Vector3(10 * forward.z, 8, -10 * forward.x); powerups.Createtele(transform.position + forward, color); } //else if (Input.GetButtonDown("Jump")) //{ // for (int i = 0; i < hitColliders.Length; i++) // { // if (hitColliders[i].tag == "tele" && powerups.tele_num == 2) // { // float d1 = Vector3.Distance(powerups.yellowbox1.transform.position, transform.position); // float d2 = Vector3.Distance(powerups.yellowbox2.transform.position, transform.position); // if (d1 < d2) // { // tilePickupAudio.PlayOneShot(mm.teleportAudio); // Vector3 off = 2 * powerups.yellowbox2.transform.TransformDirection(Vector3.up); // transform.position = powerups.yellowbox2.transform.position + new Vector3(off.x, 0, off.z); // } // else if (d1 > d2) // { // tilePickupAudio.PlayOneShot(mm.teleportAudio); // Vector3 off = 2 * powerups.yellowbox1.transform.TransformDirection(Vector3.up); // transform.position = powerups.yellowbox1.transform.position + new Vector3(off.x, 0, off.z); // } // } // if (hitColliders[i].tag == "Fixedtele") // { // teleController tc = hitColliders[i].GetComponent<teleController>(); // GameObject other = tc.teleport_other; // tilePickupAudio.PlayOneShot(mm.teleportAudio); // Vector3 off = 2 * other.transform.TransformDirection(Vector3.up); // transform.position = other.transform.position + new Vector3(off.x, 0, off.z); // } // } //} if (Input.GetButtonDown("Restart")) { Time.timeScale = 0; pauseMenu.SetActive(true); paused = true; } if (Input.GetButtonDown("Fire1") && paused && control == false) { pauseMenu.SetActive(false); jump = true; Time.timeScale = 1; paused = false; } if (Input.GetButtonDown("Fire2") && paused && control == false) { Time.timeScale = 1; paused = false; pauseMenu.SetActive(false); gm.RestartLevel(); } if (Input.GetButtonDown("Fire3") && paused && control == false) { Time.timeScale = 1; paused = false; pauseMenu.SetActive(false); gm.MainMenu(); } if (Input.GetButtonDown("Carry") && paused && control == false) { Time.timeScale = 0; pauseMenu.SetActive(false); controller.SetActive(true); control = true; } if (Input.GetButtonDown("Fire1") && paused && control == true) { Time.timeScale = 1; controller.SetActive(false); pauseMenu.SetActive(false); control = false; } if (!hitWall) { lastHit += Time.deltaTime; } msgDispTimer -= Time.deltaTime; if (msgDispTimer < 0) { msgDispTimer = 0; } if (msgDisp) { msgDisp.color = new Color(1, 1, 1, msgDispTimer / 2); } dropCarryTimer = Mathf.Max(dropCarryTimer - Time.deltaTime, 0); }
private void Update() { if (transform.position.y < -100) { gm.LoseGame(); } if (Input.GetAxis("Vertical") != 0 || Input.GetAxis("Horizontal") != 0) { curspeed += acceleration; if (curspeed > speed) { curspeed = speed; } } else if (curspeed != 0) { curspeed = 0; } float translationx = Input.GetAxis("Vertical"); float rotation = Input.GetAxis("Horizontal"); float rotationv = Input.GetAxis("Camera Vertical") * rotationSpeed; float rotationh = Input.GetAxis("Camera Horizontal") * rotationSpeed; axel.Rotate(0, 0, -0.1f * translationx); rotationv *= Time.deltaTime; rotationh *= Time.deltaTime; if (canMove) { currHorRot += rotationh; cameraAnchorH.rotation = Quaternion.Euler(0, currHorRot, 0); Rotating(rotation, translationx); Vector3 forward_direction = rb.transform.TransformDirection(Vector3.forward); Vector3 forward_velocity = new Vector3(1.1f * forward_direction.normalized.x * curspeed, rb.velocity.y, 1.1f * forward_direction.normalized.z * curspeed); rb.velocity = forward_velocity; } else { rb.velocity = new Vector3(0, rb.velocity.y, 0); } if (stationary && translationx != 0) { if (speed == 80) { animator.SetTrigger("startedSprinting"); } else { animator.SetTrigger("startedWalking"); } } stationary = translationx == 0 && rotation == 0; currVerRot = 0; var hitColliders = Physics.OverlapSphere(transform.position, 4); var hitColliderss = Physics.OverlapSphere(transform.position + new Vector3(0, 5, 0), 8); bool teleHere = false; bool engineHere = false; for (int i = 0; i < hitColliderss.Length; i++) { if (hitColliderss[i].tag == "tele" && powerups.tele_num > 0) { teleHere = true; break; } } for (int i = 0; i < hitColliders.Length; i++) { if (hitColliders[i].tag == "engine") { engineHere = true; break; } } if (Input.GetButtonDown("Fire1") && jump == true && paused == false && OnWall == false && canMove) { rb.velocity += new Vector3(0, 40, 0); tilePickupAudio.PlayOneShot(mm.jump); animator.SetTrigger("startedJumping"); jump = false; for (int i = 0; i < hitColliders.Length; i++) { if (hitColliders[i].tag == "move") { if (chat) { cc.chat.text = "Jumping on a box is fun"; } tilePickupAudio.PlayOneShot(mm.oh); } } } else if (Input.GetButtonDown("Fire1") && OnWall && paused == false && hitWall) { tilePickupAudio.PlayOneShot(mm.scared); if (chat) { cc.chat.text = Name.Myname + "," + "Do you wanna me dance on a wall or something???"; } msgDispTimer = 2; string msg = "I can not Jump here"; msgDisp.text = msg; } if (Input.GetButtonDown("Fire2") && color != Color.white) { if (Input.GetButtonDown("Fire2") && color != Color.white && canMove) { Vector3 forward = transform.TransformDirection(Vector3.forward); if (engineHere == false) { forward = new Vector3(-12 * forward.x, 5, -12 * forward.z); powerups.Createbox(transform.position + forward, color); } else { forward = new Vector3(-5 * forward.x, 5, -5 * forward.z); powerups.Createbox(transform.position + forward, color); } } } else if (Input.GetButtonDown("Fire2") && color == Color.white && carry == false) { if (chat) { cc.chat.text = Name.Myname + "," + "Do you wanna drop my heart on the ground?"; } tilePickupAudio.PlayOneShot(mm.question); msgDispTimer = 2; string msg = Name.Myname + ",there is nothing to drop"; msgDisp.text = msg; } if (Input.GetButtonDown("Fire3") && canMove && !paused) { powerups.GetEnginePower(transform.position); } if (Input.GetButtonDown("Fire3") && (color == Color.blue) && teleHere) { for (int i = 0; i < hitColliderss.Length; i++) { if (chat) { cc.chat.text = Name.Myname + "," + "Guess you put a portal in a wrong place, try to find a better place"; } tilePickupAudio.PlayOneShot(mm.ah); if (hitColliderss[i].tag == "tele" && powerups.tele_num > 0) { Destroy(hitColliderss[i].gameObject); powerups.tele_num--; //if (powerups.yellowbox1 != null && powerups.tele_num == 1) //{ // Debug.Log("get1"); // powerups.yellowbox2 = null; //} //else if (powerups.yellowbox2 != null && powerups.tele_num == 1) //{ // Debug.Log("get2"); // powerups.yellowbox1 = powerups.yellowbox2; // powerups.yellowbox2 = null; //} } } } else if (Input.GetButtonDown("Fire3") && carry == false) { bool boxhere = false; for (int i = 0; i < hitColliders.Length; i++) { if (hitColliders[i].tag == "move") { carryThing = (hitColliders[i].gameObject); boxhere = true; carry = true; dropCarryTimer = 0.5f; tilePickupAudio.PlayOneShot(mm.pickUpBox); carryStart = carryThing.transform.position; float df = (carryStart - front.position).sqrMagnitude; float db = (carryStart - back.position).sqrMagnitude; float dl = (carryStart - left.position).sqrMagnitude; float dr = (carryStart - right.position).sqrMagnitude; if (df < db && df < dr && df < dl) { carryTo = front.position; } else if (db < dr && db < dl) { carryTo = back.position; } else if (dr < dl) { carryTo = right.position; } else { carryTo = left.position; } tilePickupAudio.PlayOneShot(mm.happy); if (chat) { cc.chat.text = "I am carrying an object, where should I put it?"; } for (int j = 0; j < carryThing.transform.childCount; j++) { Transform c = carryThing.transform.GetChild(j); if (c.CompareTag("robot_light")) { c.gameObject.SetActive(true); } } } //if (boxhere == false && engineHere == false && teleHere == false && carry == false) //{ // if (chat) // { // cc.chat.text = Name.Myname + "," + "What do you wanna pick up? Maybe you should get closer"; // } // tilePickupAudio.PlayOneShot(mm.question); // msgDispTimer = 2; // string msg = "There is nothing to pick up"; // msgDisp.text = msg; //} //tilePickupAudio.PlayOneShot(mm.blastAudio); } } else if (Input.GetButtonDown("Fire2") && carry) { if (hitColliders.Length < 5) { if (dropCarryTimer <= 0) { Vector3 forward = transform.TransformDirection(Vector3.left); forward = new Vector3(3 * forward.z, 2, -3 * forward.x); carryThing.transform.position = transform.position + forward; carry = false; tilePickupAudio.PlayOneShot(mm.putDownBox); dropCarryTimer = 0.5f; if (carryThing.GetComponent <Float>()) { carryThing.GetComponent <Float>().begin = carryThing.transform.position; } for (int j = 0; j < carryThing.transform.childCount; j++) { Transform c = carryThing.transform.GetChild(j); if (c.CompareTag("robot_light")) { c.gameObject.SetActive(false); } } tilePickupAudio.PlayOneShot(mm.question); if (chat) { cc.chat.text = "emmmmmmmm.......... " + Name.Myname + "," + "Do you think this is the right position to put this box???"; } } } else if (msgDisp) { msgDispTimer = 2; string msg = "I can not place box here."; tilePickupAudio.PlayOneShot(mm.scared); msgDisp.text = msg; if (chat) { cc.chat.text = "There are too many things here. I can not put a box here"; } } } if (carry && carryThing) { //carryThing.transform.position = transform.position + new Vector3(0, 15, 0); if (dropCarryTimer > 0.25f) { carryThing.transform.position = Vector3.Slerp(carryStart, carryTo, 4 * (0.5f - dropCarryTimer)); } else { carryThing.transform.position = Vector3.Slerp(carryTo, transform.position + new Vector3(0, 15, 0), 4 * (0.25f - dropCarryTimer)); } } if (Input.GetKey("r")) { gm.RestartLevel(); } if (Input.GetButtonDown("Jump") && (color == Color.red)) { bool nothing = true; for (int i = 0; i < hitColliders.Length; i++) { if (hitColliders[i].tag == "blast") { Instantiate(blastFire, hitColliders[i].gameObject.transform.position + new Vector3(0, -10, 0), Quaternion.identity); Destroy(hitColliders[i].gameObject); tilePickupAudio.PlayOneShot(mm.blastAudio); tilePickupAudio.PlayOneShot(mm.ability); if (chat) { cc.chat.text = "Bomb!!!!!"; } nothing = false; } } if (nothing) { if (chat) { cc.chat.text = Name.Myname + "," + "Do you wanna me to blast air???"; } msgDispTimer = 2; string msg = Name.Myname + ", there is nothing to blast"; msgDisp.text = msg; ; tilePickupAudio.PlayOneShot(mm.question); } } if (Input.GetButton("Jump") && color == Color.green) { tilePickupAudio.PlayOneShot(mm.runfasterAudio); speed = 80; if (chat) { cc.chat.text = "Speed up!!!!!"; } fire.SetActive(true); } else { fire.SetActive(false); speed = 40; } if (Input.GetButtonDown("Jump") && (color == Color.blue) && powerups.tele_num < 2) { if (chat) { cc.chat.text = Name.Myname + "," + "Remember put portal in a spacious place.Otherwise you will wanna take them back later"; } Vector3 forward = transform.TransformDirection(Vector3.left); forward = new Vector3(5 * forward.z, 8, -5 * forward.x); powerups.Createtele(transform.position + forward, color); } //else if (Input.GetButtonDown("Jump")) //{ // for (int i = 0; i < hitColliders.Length; i++) // { // if (hitColliders[i].tag == "tele" && powerups.tele_num == 2) // { // float d1 = Vector3.Distance(powerups.yellowbox1.transform.position, transform.position); // float d2 = Vector3.Distance(powerups.yellowbox2.transform.position, transform.position); // if (d1 < d2) // { // tilePickupAudio.PlayOneShot(mm.teleportAudio); // Vector3 off = 2 * powerups.yellowbox2.transform.TransformDirection(Vector3.up); // transform.position = powerups.yellowbox2.transform.position + new Vector3(off.x, 0, off.z); // } // else if (d1 > d2) // { // tilePickupAudio.PlayOneShot(mm.teleportAudio); // Vector3 off = 2 * powerups.yellowbox1.transform.TransformDirection(Vector3.up); // transform.position = powerups.yellowbox1.transform.position + new Vector3(off.x, 0, off.z); // } // } // // if (hitColliders[i].tag == "Fixedtele") // // { // // teleController tc = hitColliders[i].GetComponent<teleController>(); // // GameObject other = tc.teleport_other; // // tilePickupAudio.PlayOneShot(mm.teleportAudio); // // Vector3 off = 2 * other.transform.TransformDirection(Vector3.up); // // transform.position = other.transform.position + new Vector3(off.x, 0, off.z); // // } // // } // } //} if (Input.GetButtonDown("Restart") && canMove == true) { Time.timeScale = 0; pauseMenu.SetActive(true); paused = true; canMove = false; } if (Input.GetButtonDown("Fire1") && paused && control == true) { Time.timeScale = 1; controller.SetActive(false); pauseMenu.SetActive(false); control = false; canMove = true; paused = false; } if (!hitWall) { lastHit += Time.deltaTime; } msgDispTimer -= Time.deltaTime; if (msgDispTimer < 0) { msgDispTimer = 0; } if (msgDisp) { msgDisp.color = new Color(1, 1, 1, msgDispTimer / 2); } dropCarryTimer = Mathf.Max(dropCarryTimer - Time.deltaTime, 0); }