예제 #1
0
    public void FireWeapon(int type)
    {
        // Main Weapon
        switch (type)
        {
        case 1:         // Laser
            laserController.gameObject.SetActive(true);
            laserController.FireLaser();
            break;

        case 2:         // Ripple

            break;

        case 0:         // For normal attack
        default:
            for (int i = 0; i < shotPool_shots.objects.Count; i++)
            {
                GameObject currentShot = shotPool_shots.objects[i];
                if (!currentShot.activeInHierarchy)
                {
                    currentShot.transform.position = shotOrigin.position;
                    currentShot.SetActive(true);
                    SetFiringAnimation();

                    // Assign effect from effects pool to attack shot
                    // Foreach deprecated due to being slower than For loop in context of handling List contents
                    if (shotPool_shots.effectsObjectPool)
                    {
                        //foreach(GameObject effectObject in shotPool_shots.effectsObjectPool.objects) {
                        for (int j = 0; j < shotPool_shots.effectsObjectPool.objects.Count; j++)
                        {
                            GameObject currentShotEffect = shotPool_shots.effectsObjectPool.objects[j];
                            if (!currentShotEffect.activeInHierarchy)
                            {
                                currentShotEffect.transform.GetComponent <PlayerShotParticle_Controller>().SetFollowPlayerStatus(currentShot.transform);
                                currentShotEffect.SetActive(true);
                                break;
                            }
                        }
                    }
                    break;
                }
            }
            break;
        }
    }
    void PlayerInput()
    {
        bool isMovingx = false;
        bool isMovingy = false;


        if (Input.GetAxis("Mouse X") != 0 || Input.GetAxis("Mouse Y") != 0)
        {
            oldCameraRotation = cameraTransform.rotation;
            // get left to right mouse movement
            float yRot = Input.GetAxis("Mouse X") * rotationSpeed;

            // get up and down mouse movement
            float xRot = Input.GetAxis("Mouse Y") * cameraSpeed;

            // rotate the player model left and right
            transform.localRotation *= Quaternion.Euler(0f, yRot, 0f);

            // rotates the camera up and down
            laserTransform.localRotation  *= Quaternion.Euler(-xRot, 0f, 0f);
            laserTransform2.localRotation *= Quaternion.Euler(-xRot, 0f, 0f);
            cameraTransform.localRotation *= Quaternion.Euler(-xRot, 0f, 0f);

            // clamps the max up and down view
            cameraTransform.localRotation = ClampRotationAroundXAxis(cameraTransform.localRotation);
        }

        if ((Input.GetKey(KeyCode.Space) || Input.GetMouseButton(0)) && RemainingLaserCharge())
        {
            if (cameraTransform.rotation != oldCameraRotation)
            {
                laserControllerScript.FireLaser(cameraTransform.rotation);
            }
            if (laserParticleStart)
            {
                laserObject.GetComponent <ParticleSystem>().Play();
                laserObject2.GetComponent <ParticleSystem>().Play();
                laserParticleStart = false;
            }
        }
        else if (Input.GetKeyUp(KeyCode.Space) || Input.GetMouseButtonUp(0))
        {
            laserControllerScript.HaltLaser();
            laserParticleStart = true;
        }
        else if (laserCharge < 1)
        {
            laserControllerScript.HaltLaser();
            laserObject.GetComponent <ParticleSystem>().Stop();
            laserObject2.GetComponent <ParticleSystem>().Stop();
        }

        if (Input.GetKeyDown("r") && !reloading)
        {
            if (potionCount > 0)
            {
                charController.SetBool("drink", true);
                ChangePotionCount(-1);
                SetLaserCharge(laserChargeMax);
                reloading = true;
            }
        }
        else
        {
            reloading = false;
            //charController.SetBool("drink", false);
        }


        if (Input.GetKeyUp(KeyCode.Space) || Input.GetMouseButtonUp(0))
        {
            laserObject.GetComponent <ParticleSystem>().Stop();
            laserObject2.GetComponent <ParticleSystem>().Stop();
        }

        if (Input.GetKey("w") && Input.GetKey("s"))
        {
            isMovingx = false;
        }
        else if (Input.GetKey(KeyCode.LeftShift) && Input.GetKey("w"))
        {
            transform.position += transform.TransformDirection(Vector3.forward) * Time.deltaTime * movementForwardSpeed * 2.5f;
            isMovingx           = true;
        }
        else if (Input.GetKey("w"))
        {
            transform.position += transform.TransformDirection(Vector3.forward) * Time.deltaTime * movementForwardSpeed;
            isMovingx           = true;
        }
        else if (Input.GetKey("s"))
        {
            transform.position += transform.TransformDirection(-Vector3.forward) * Time.deltaTime * movementBackwardSpeed;
            isMovingx           = true;
        }
        else
        {
            isMovingx = false;
        }



        if (Input.GetKey("a") && Input.GetKey("d"))
        {
            isMovingy = false;
        }
        else if (Input.GetKey("a"))
        {
            transform.position += transform.TransformDirection(Vector3.left) * Time.deltaTime * strafeSpeed;
            isMovingy           = true;
        }
        else if (Input.GetKey("d"))
        {
            transform.position += transform.TransformDirection(Vector3.right) * Time.deltaTime * strafeSpeed;
            isMovingy           = true;
        }

        if (isMovingx || isMovingy)
        {
            charController.SetInteger("walk", 1);
        }
        else
        {
            charController.SetInteger("walk", 0);
        }

        if (Input.GetKey("e"))
        {
            potionControllerScript.GrabPotion();
        }



        if ((Input.GetKey(KeyCode.LeftControl) || Input.GetKey("c")) && crouching == false)
        {
            cameraTransform.position += new Vector3(0, crouchDistance * -1, 0);

            crouching = true;
        }
        else if ((Input.GetKeyUp(KeyCode.LeftControl) || Input.GetKeyUp("c")) && crouching == true)
        {
            cameraTransform.position += new Vector3(0, crouchDistance, 0);
            crouching = false;
        }
    }