private bool IsBlocked(Vector3 direction, char[,] grid) { Vector3 newPosition = transform.position + direction; GameObject[] allWalls = GameObject.FindGameObjectsWithTag("Wall"); foreach (var wall in allWalls) { if (wall.transform.position == newPosition) { return(true); } } GameObject[] allMovableBoxes = GameObject.FindGameObjectsWithTag("MovableBox"); foreach (var movableBox in allMovableBoxes) { if (movableBox.transform.position == newPosition) { MovableBox box = movableBox.GetComponent <MovableBox>(); if (box.BoxMove(direction, grid)) { return(false); } else { return(true); } } } return(false); }
public void ThrowBox(MovableBox box, Vector3 velocity) { var throwPower = 5f; var throwVector = (Transform.forward + Transform.up) * throwPower; var boxVelocity = throwVector + velocity; box.ResetParent(); box.EnablePhysics(boxVelocity); }
private void OnBoxDestroyed(MovableBox box) { _boxes.Remove(box); var count = _boxes.Count; _guiManager.GuiHooks.BoxAmount = count.ToString(); if (count <= 0) { Finish(); } }
private void CheckInteract() { // Declare a raycast hit to store information about what our raycast has hit RaycastHit hit; switch (state) { case PlayerState.Carrying: //disable laser line laserLine.enabled = false; if (Input.GetKeyUp("e")) { state = PlayerState.NotCarrying; //drop audioSource.clip = interactSound; audioSource.Play(); interactText.text = "[E] Pick Up"; //move.IsPickedUp = false; moveRb.useGravity = true; moveRb.freezeRotation = false; Destroy(joint); moveRb.transform.parent = null; moveRb = null; } break; case PlayerState.NotCarrying: //is interactable object in range? if (Physics.Raycast(rayOrigin, fpsCam.transform.forward, out hit, interactRange)) { moveObject = hit.collider.gameObject; moveRp = moveObject.GetComponent <ReturnPad> (); move = moveObject.GetComponent <MovableBox> (); moveRb = moveObject.GetComponent <Rigidbody> (); if (moveRp != null) // if you're looking at the return pad { interactText.text = "[E] Use return pad"; interactText.enabled = true; if (Input.GetKeyUp("e")) { // play some sound //audioSource.clip = interactSound; //audioSource.Play (); moveRp.Return(); } } else if (move != null) //if box is movable { interactText.text = "[E] Pick Up"; interactText.enabled = true; if (Input.GetKeyUp("e")) { state = PlayerState.Carrying; AddJoint(); // pick up audioSource.clip = interactSound; audioSource.Play(); interactText.text = "[E] Drop"; moveRb.useGravity = false; moveRb.freezeRotation = true; moveRb.transform.SetParent(fpsCam.transform); } } else { interactText.enabled = false; } } else { interactText.enabled = false; } break; } }
private void CheckShoot() { // Declare a raycast hit to store information about what our raycast has hit RaycastHit hit; // Check if the player has pressed the warp button if (Input.GetButtonDown("Fire2")) { //////////////////PLAY AUDIO////////////////// audioSource.clip = warpSound; audioSource.Play(); //////////////////USE RAYCAST////////////////// // Check if our raycast has hit anything if (Physics.Raycast(rayOrigin, fpsCam.transform.forward, out hit, weaponRange)) { move = hit.collider.GetComponent <MovableBox>(); if (move != null) { //Wait? move.Warp(); } } } else if (Input.GetButton("Fire1")) { //////////////////PLAY AUDIO////////////////// audioSource.clip = gunSound; // Play the shooting sound effect if (!audioSource.isPlaying) { audioSource.Play(); } //////////////////USE RAYCAST////////////////// // Turn on our line renderer laserLine.enabled = true; // Set the start position for our visual effect for our laser to the position of gunEnd laserLine.SetPosition(0, gunEnd.position); laserParticles.Play(); // Check if our raycast has hit anything if (Physics.Raycast(rayOrigin, fpsCam.transform.forward, out hit, weaponRange)) { // Set the end position for our laser line laserLine.SetPosition(1, hit.point); //laserLine.SetPosition(0, hit.point); //laserLine.SetPosition(1, hit.point + hit.normal); move = hit.collider.GetComponent <MovableBox> (); // Check if the object we hit is movable if (move == null) { return; } //all movable objects have rigidbodies hit.rigidbody.freezeRotation = true; //hitting a different object if (hit.rigidbody != lastRb) { UnfreezeLastObject(); lastRb = hit.rigidbody; } // Add force to the rigidbody we hit, in the direction from which it was hit hit.rigidbody.AddForce(-hit.normal * hitForce); } else { // If we did not hit anything, set the end of the line to a position directly in front of the camera at the distance of weaponRange UnfreezeLastObject(); laserLine.SetPosition(1, rayOrigin + (fpsCam.transform.forward * weaponRange)); } } else //neither button pressed, end beam { UnfreezeLastObject(); laserLine.enabled = false; if (audioSource.clip == gunSound) { audioSource.Stop(); } laserParticles.Stop(); laserParticles.Clear(); } }