private void UpdatePickupPosition() { if (currentItem == null) { return; } currentItem.GetGameObject().transform.position = cam.transform.position - cam.transform.up * 1f + cam.transform.forward * holdDistance; currentItem.GetGameObject().transform.rotation = cam.transform.rotation; }
// Update is called once per frame protected virtual void Update() { if (currentItem != null) { GameObject go = currentItem.GetGameObject(); go.transform.position = transform.position; go.transform.rotation = transform.rotation; } }
// Update is called once per frame void Update() { if (pickedUp != null) { pickUpPublic = pickedUp.GetGameObject(); } else { pickUpPublic = null; } if (Time.timeScale > 0) { if (currentMode == PlayerMode.LOCKER) { } if (currentMode == PlayerMode.ELEVATOR) { if (myDrone && !myDrone.GetComponent <ReconnaissanceDrone> ().GetComponent <Animator> ().GetBool("dying")) { myDrone.GetComponent <ReconnaissanceDrone> ().Die(); } if (pickedUp != null) { if (pickedUp.GetGameObject().GetComponent <IEnemy> () == null) { Throw(); } } } if (currentMode == PlayerMode.PLAYER) { float move = Input.GetAxis("Horizontal"); float crouch = Input.GetAxis("Vertical"); float stickAngle = Mathf.Round(Mathf.Atan2(Input.GetAxis("Vertical"), Input.GetAxis("Horizontal")) * Mathf.Rad2Deg / 45f) * 45f; myAnim.SetFloat("angle", CalculateAngle(stickAngle)); bool fire = Input.GetKey(KeyCode.Joystick1Button19) || Input.GetKey(KeyCode.K); aiming = Input.GetAxis("Aiming") > 0 || Input.GetKey(KeyCode.H); bool pistol = Input.GetKey(KeyCode.Joystick1Button1); bool running = Input.GetKey(KeyCode.Joystick1Button18) || Input.GetKey(KeyCode.L); bool pulling = Input.GetKey(KeyCode.Joystick1Button13) || Input.GetKey(KeyCode.F); bool jumping = Input.GetKeyDown(KeyCode.Joystick1Button16) || Input.GetKey(KeyCode.J); float notMoving = (Mathf.Abs(myRB.velocity.x) + Mathf.Abs(myRB.velocity.y)); bool wasPressedThisUpdate = pistol; InventoryCycle(); Running(running); if (!firstFadeOut) { fadeOut = Time.time + 10f; firstFadeOut = true; } if ((Time.time > fadeOut)) { FadeChildren(); money.GetComponent <Text> ().CrossFadeAlpha(0, .5f, true); if (!underWater) { oxygenUi.GetComponent <FadeAll> ().currentMode = FadeAll.FadeMode.FADEOUT; } } if (grounded && (jumping) && !dead) { Jump(); } if (turning > 0) { myAnim.SetBool("turning", true); turning--; } else { myAnim.SetBool("turning", false); } grounded = Physics2D.OverlapCircle(groundCheck.position, groundCheckRadius, groundLayer); platformed = Physics2D.OverlapCircle(groundCheck.position, groundCheckRadius, platformLayer); walled = Physics2D.OverlapCircle(transform.position, groundCheckRadius + 1, wallLayer); lava = Physics2D.OverlapCircle(transform.position, groundCheckRadius, lavaLayer); if (lava) { Damage(); } if (platformed) { grounded = true; } if (walled && !grounded && (jumping)) { Debug.Log(walled); // Jump (); // myRB.AddForce (-transform.right * 200, ForceMode2D.Impulse); myRB.AddForce(new Vector2(Mathf.Clamp(-myRB.velocity.x * 5f, 1f, 30f), jumpPower * Input.GetAxis("Fire1")), ForceMode2D.Impulse); myRB.AddForce(new Vector2(-jumpPower * Input.GetAxis("Fire1") * transform.forward.x, 0f), ForceMode2D.Impulse); Flip(); } myAnim.SetBool("grounded", grounded); Crouch(crouch); if (move > 0 && !facingRight && !dead) { Flip(); } else if (move < 0 && facingRight && !dead) { Flip(); } wasPressedLastUpdate = wasPressedThisUpdate; if (aiming == false && crouching == false && dead == false && pulling == false) { myRB.velocity = new Vector2(move * maxSpeed, myRB.velocity.y); } myAnim.SetFloat("moveSpeed", Mathf.Abs(move)); myAnim.SetBool("crouching", crouching); myAnim.SetBool("aiming", im.HasWeapon() ? aiming : false); myAnim.SetBool("running", running); myAnim.SetBool("pulling", pulling); myAnim.SetFloat("notMoving 0", notMoving); if (aiming && pickedUp == null) { myAnim.SetInteger("aimingDirection", Mathf.RoundToInt(crouch)); if (fire) { Fire(stickAngle); } if (Input.GetKey(KeyCode.C) || Input.GetKey(KeyCode.Joystick1Button17)) { ThrowGrenade(stickAngle); } } if (pickedUp != null && Input.GetKeyDown(KeyCode.Joystick1Button17)) { Throw(); } } if (currentMode == PlayerMode.DRONE) { Debug.Log("SWITCH MODES"); if (Input.GetKeyDown(KeyCode.Joystick1Button13)) { currentMode = PlayerMode.PLAYER; gameObject.tag = "Player"; } } else if ((Input.GetKeyDown(KeyCode.Joystick1Button12) || Input.GetKeyDown(KeyCode.U)) && currentMode == PlayerMode.PLAYER) { DeployDrone(); } if (health <= 0 && !dead) { Die(); } if (currentMode == PlayerMode.LADDER) { Debug.Log("ladder"); float climbSpeed = maxSpeed * Time.deltaTime; if (Input.GetAxis("Vertical") > 0) { Debug.Log("ladder up"); transform.Translate(Vector3.up * 0.2f); if (transform.position.y > ladder.GetComponent <Collider2D> ().bounds.max.y || transform.position.y < ladder.GetComponent <Collider2D> ().bounds.min.y) { NotClimbing(); } } else if (Input.GetAxis("Vertical") < 0) { Debug.Log("ladder down"); transform.Translate(-Vector3.up * 0.2f); if (transform.position.y > ladder.GetComponent <Collider2D> ().bounds.max.y || transform.position.y < ladder.GetComponent <Collider2D> ().bounds.min.y) { NotClimbing(); } } } if (currentMode == PlayerMode.PICKUP) { currentMode = PlayerMode.PLAYER; } } rm.Run(); UpdateHud(); }
private void CheckPickup() { if (actionButtonDown) { //If we have an object... if (currentItem != null) { //And we look at something... IHolder holder = null; RaycastHit hit; if (UnityEngine.Physics.Raycast(cam.transform.position, cam.transform.forward, out hit, pickupRange)) { //If it's a holder holder = hit.collider.gameObject.GetComponent <IHolder>(); } //If it isn't null.. if (holder != null && !holder.CheckHoldingObject()) { //Make it hold our released object IPickupable releasedObject = ReleaseObject(); releasedObject.GetGameObject().transform.position = hit.point + hit.normal * 0.1f; holder.HoldObject(releasedObject); audioSource.Play(); } else { //Otherwise release our object IPickupable releasedItem = ReleaseObject(); GameObject releasedGameObject = releasedItem.GetGameObject(); if (hit.collider != null) { releasedGameObject.transform.position = hit.point + hit.normal * 0.1f; releasedGameObject.transform.rotation = Quaternion.LookRotation(hit.normal, Vector3.up); } } } else { //If we don't have an object and we are looking at something... RaycastHit hit; if (UnityEngine.Physics.Raycast(cam.transform.position, cam.transform.forward, out hit, pickupRange)) { //If the item is a pickup... IPickupable pickup = hit.collider.gameObject.GetComponent <IPickupable>(); if (pickup != null) { //Pick up the object HoldObject(pickup); } else { //And we look at a holder... IHolder holder = hit.collider.gameObject.GetComponent <IHolder>(); if (holder != null) { //And it holds an object... if (holder.CheckHoldingObject()) { //Get it from the holder IPickupable releasedObject = holder.ReleaseObject(); releasedObject.GetGameObject().transform.position = hit.point + hit.normal * 0.1f; HoldObject(releasedObject); } } } } } } }