Пример #1
0
    void Update()
    {
        //*Movement Input
        //GetAxisRaw removes smoothing of movement
        Vector3 moveInput    = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical"));
        Vector3 moveVelocity = Vector3.Normalize(moveInput) * moveSpeed;

        pController.Move(moveVelocity);
        //Kill player if fall off
        if (transform.position.y < -10)
        {
            TakeDamage(health);
        }

        //*Look Input
        //Cast ray from camera to mouse position
        Ray   ray         = viewCamera.ScreenPointToRay(Input.mousePosition);
        Plane groundPlane = new Plane(Vector3.up, Vector3.up * gController.GunHeight);
        float rayDistance;

        //Intersect ray with plane, returns true if intersected, outputs ray distance
        if (groundPlane.Raycast(ray, out rayDistance))
        {
            //Get point along ray with rayDistance
            Vector3 pointOfIntersection = ray.GetPoint(rayDistance);
            //Debug.DrawLine(ray.origin, pointOfIntersection, Color.red);
            pController.LookAt(pointOfIntersection);
            crosshairs.transform.position = pointOfIntersection;
            crosshairs.DetectTargets(ray);
            if ((new Vector2(pointOfIntersection.x, pointOfIntersection.z) - new Vector2(transform.position.x, transform.position.y)).sqrMagnitude > 1)
            {
                gController.Aim(pointOfIntersection);
            }
        }
        //*Weapon Input
        if (Input.GetMouseButton(0))
        {
            gController.OnTriggerHold();
        }
        if (Input.GetMouseButtonUp(0))
        {
            gController.OnTriggerRelease();
        }
        if (Input.GetKeyDown(KeyCode.R))
        {
            gController.Reload();
        }
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            SceneManager.LoadScene("Menu");
        }
    }
Пример #2
0
        void Update()
        {
            if (GameUI.IsPaused)
            {
                return;
            }

            // Movement input
            Vector3 moveInput    = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical"));
            Vector3 moveVelocity = moveInput.normalized * moveSpeed;

            controller.Move(moveVelocity);

            // Look input
            Ray   ray         = viewCamera.ScreenPointToRay(Input.mousePosition);
            Plane groundPlane = new Plane(Vector3.up, Vector3.up * gunController.GunHeight);
            float rayDistance;

            if (groundPlane.Raycast(ray, out rayDistance))
            {
                Vector3 point = ray.GetPoint(rayDistance);
                Debug.DrawLine(ray.origin, point, Color.red);
                controller.LookAt(point);
                crosshairs.transform.position = point;
                crosshairs.DetectTargets(ray);

                if ((new Vector2(point.x, point.z) - new Vector2(transform.position.x, transform.position.z)).magnitude > 1)
                {
                    gunController.Aim(point);
                }
            }

            // Weapon input
            if (Input.GetMouseButton(0))
            {
                gunController.OnTriggerHold();
            }
            if (Input.GetMouseButtonUp(0))
            {
                gunController.OnTriggerRelease();
            }
            if (Input.GetKeyDown(KeyCode.R))
            {
                gunController.Reload();
            }

            if (transform.position.y < -10)
            {
                TakeDamage(Health);
            }
        }
Пример #3
0
    // Update is called once per frame
    void Update()
    {
        //movement input
        Vector3 moveInput    = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical"));
        Vector3 moveVelocity = moveInput.normalized * moveSpeed;

        controller.Move(moveVelocity);

        //look input
        Ray   ray         = viewCamera.ScreenPointToRay(Input.mousePosition);
        Plane groundPlane = new Plane(Vector3.up, Vector3.up * transform.position.y);
        float rayDistance;

        if (groundPlane.Raycast(ray, out rayDistance)) //will return true if it intersepts with the ground plane
        {
            Vector3 point = ray.GetPoint(rayDistance); //returns the point that the ray has hit the plane

            //Debug.DrawLine(ray.origin, point, Color.red);
            controller.LookAt(point);
            crosshairs.transform.position = point;
            crosshairs.DetectTargets(ray);
            //sqr magnitude faster than normal magnitude
            if ((new Vector2(point.x, point.z) - new Vector2(transform.position.x, transform.position.z)).sqrMagnitude > 2)
            {
                gunController.Aim(point);
            }
        }

        //weapon input
        if (Input.GetMouseButton(0))
        {
            gunController.OnTriggerHold();
        }

        if (Input.GetMouseButtonUp(0))
        {
            gunController.OnTriggerRelease();
        }

        if (Input.GetKeyDown(KeyCode.R))
        {
            gunController.Reload();
        }

        if (transform.position.y < -10)
        {
            TakeDamage(health);
        }
    }
Пример #4
0
    void Update()
    {
        //  MOVEMENT INPUT
        Vector3 moveInput    = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical"));
        Vector3 moveVelocity = moveInput.normalized * moveSpeed;

        playerController.Move(moveVelocity);      //  questa funzione sarà nel controller

        //  LOOK INPUT
        Ray   ray         = viewCamera.ScreenPointToRay(Input.mousePosition);
        Plane groundPlane = new Plane(Vector3.up, Vector3.up * gunController.GunHeight);
        float rayDistance;

        if (groundPlane.Raycast(ray, out rayDistance))
        {
            Vector3 point = ray.GetPoint(rayDistance);
            //  Debug.DrawLine(ray.origin, point, Color.red);
            playerController.LookAt(point);
            crosshairs.transform.position = point;
            crosshairs.DetectTargets(ray);

            if ((new Vector2(point.x, point.z) - new Vector2(transform.position.x, transform.position.z)).sqrMagnitude > 2)
            {
                gunController.Aim(point);
            }
        }

        //  DIE IF FALLING
        if (transform.position.y < -10)         //  TODO: smooth damage
        {
            TakeDamage(health);
        }


        //  WEAPON INPUT
        if (Input.GetMouseButton(0))
        {
            gunController.OnTriggerHold();
        }
        if (Input.GetMouseButtonUp(0))
        {
            gunController.OnTriggerRelease();
        }
        if (Input.GetKeyDown(KeyCode.R))
        {
            gunController.Reload();
        }
    }
Пример #5
0
    protected override void Update()
    {
        base.Update();

        // Movement input
        Vector3 moveInput    = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical")).normalized;
        Vector3 moveVelocity = moveInput * moveSpeed;

        controller.Move(moveVelocity);

        // Look input
        //Plane groundPlane = new Plane(Vector3.up, Vector3.zero);
        Plane groundPlane = new Plane(Vector3.up, Vector3.up * _verticalOffset);
        Ray   ray         = viewCamera.ScreenPointToRay(Input.mousePosition);
        float distanceToGroundPlane;

        if (groundPlane.Raycast(ray, out distanceToGroundPlane))
        {
            Vector3 pointOfIntersection = ray.GetPoint(distanceToGroundPlane);
            pointOfIntersection = new Vector3(pointOfIntersection.x, _verticalOffset, pointOfIntersection.z);
            controller.LookAt(pointOfIntersection);
            crosshairs.transform.position = pointOfIntersection;
            crosshairs.DetectTargets(ray);

            if (Vector2.Distance(new Vector2(pointOfIntersection.x, pointOfIntersection.z), new Vector2(transform.position.x, transform.position.z)) > enableAimingRadius)
            {
                gunCtrl.Aim(pointOfIntersection);
            }
        }

        // Weapon input
        if (Input.GetMouseButtonUp(0))
        {
            gunCtrl.OnTriggerRelease();
        }
        if (Input.GetMouseButtonDown(0))
        {
            gunCtrl.OnTriggerHold();
        }
        if (Input.GetMouseButtonDown(1))
        {
            gunCtrl.Reload();
        }

        CameraFollowPlayer();
    }
Пример #6
0
    // Update is called once per frame
    void Update()
    {
        // Movement Input
        Vector3 moveInput    = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical"));
        Vector3 moveVelocity = moveInput.normalized * moveSpeed;

        controller.Move(moveVelocity);

        // Look input
        Ray   ray         = viewCamera.ScreenPointToRay(Input.mousePosition);
        Plane groundPlane = new Plane(Vector3.up, Vector3.up * gunController.GunHeight); // we need to intersect the ray with the ground plane to see where the player will be looking - so make a flat plane
        float rayDistance;

        if (groundPlane.Raycast(ray, out rayDistance)) // if ray intersects with ground plane
        {
            Vector3 pointOfIntersection = ray.GetPoint(rayDistance);
            Debug.DrawLine(ray.origin, pointOfIntersection, Color.red);
            controller.LookAt(pointOfIntersection);
            crosshairs.transform.position = pointOfIntersection;
            crosshairs.DetectTargets(ray);
            if ((new Vector2(pointOfIntersection.x, pointOfIntersection.z) - new Vector2(transform.position.x, transform.position.z)).sqrMagnitude >= 1)
            {
                gunController.Aim(pointOfIntersection);
            }
            {
            }
        }

        // Weapon input
        if (Input.GetMouseButton(0))
        {
            gunController.OnTriggerHold();
        }
        if (Input.GetMouseButtonUp(0))
        {
            gunController.OnTriggerRelease();
        }
        if (Input.GetKeyDown(KeyCode.R))
        {
            gunController.Reload();
        }
        if (transform.position.y <= -10)
        {
            TakeDamage(health);
        }
    }
Пример #7
0
    private void LookInput()
    {
        Ray   ray         = _viewCamera.ScreenPointToRay(Input.mousePosition);
        Plane groundPlane = new Plane(Vector3.up, Vector3.up * _gunController.GunHeight);

        if (groundPlane.Raycast(ray, out float rayDistance))
        {
            Vector3 point = ray.GetPoint(rayDistance);
            //Debug.DrawLine(ray.origin, point, Color.red);
            _controller.LookAt(point);
            Crosshairs.transform.position = point;
            Crosshairs.DetectTargets(ray);

            if ((new Vector2(point.x, point.z) - new Vector2(transform.position.x, transform.position.z)).sqrMagnitude > 1)
            {
                _gunController.Aim(point);
            }
        }
    }
Пример #8
0
    private void Update()
    {
        // Movement input
        Vector3 moveInput    = new Vector3(Input.GetAxisRaw("Horizontal"), 0.0f, Input.GetAxisRaw("Vertical"));
        Vector3 moveVelocity = moveInput.normalized * moveSpeed;

        mController.Move(moveVelocity);

        // Look input
        Ray   ray           = mMainCam.ScreenPointToRay(Input.mousePosition);
        Plane virtualGround = new Plane(Vector3.up, Vector3.up * mGunController.GunHeight);
        float rayDistance;

        if (virtualGround.Raycast(ray, out rayDistance))
        {
            Vector3 endPoint = ray.GetPoint(rayDistance);
            // Debug.DrawLine(ray.origin, endPoint, Color.black);
            mController.LookAt(endPoint);
            crosshairs.transform.position = endPoint;
            crosshairs.DetectTargets(ray);
            if ((new Vector2(endPoint.x, endPoint.z) - new Vector2(transform.position.x, transform.position.z)).sqrMagnitude > 2 * 2)
            {
                mGunController.Aim(endPoint);
            }
        }

        // Weapon input
        if (Input.GetMouseButton(0))
        {
            mGunController.OnTriggerHold();
        }
        if (Input.GetMouseButtonUp(0))
        {
            mGunController.OnTriggerRelease();
        }

        //out of world edge
        if (transform.position.y < -5f)
        {
            TakeHitWithDamage(health);
        }
    }
Пример #9
0
    void Update()
    {
        //移动
        Vector3 moveInput    = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical"));
        Vector3 moveVelpcity = moveInput.normalized * moveSpeed;

        playerController.Move(moveVelpcity);

        //转向
        Ray   ray   = camera.ScreenPointToRay(Input.mousePosition);
        Plane plane = new Plane(Vector3.up, Vector3.up * gunController.gunHeight);
        float rayDistance;

        if (plane.Raycast(ray, out rayDistance))
        {
            Vector3 point = ray.GetPoint(rayDistance);
            //Debug.DrawLine(ray.origin, point, Color.red);
            playerController.LookAt(point);
            crosshairs.transform.position = point;
            crosshairs.DetectTargets(ray);
            if ((new Vector2(point.x, point.z) - new Vector2(transform.position.x, transform.position.z)).sqrMagnitude > 0.5f)
            {
                gunController.Aim(point);
            }
        }
        //射击
        if (Input.GetMouseButton(0))
        {
            gunController.OnTriggerHold();
        }
        if (Input.GetMouseButtonUp(0))
        {
            gunController.OnTriggerRelease();
        }
        if (Input.GetKeyDown(KeyCode.R))
        {
            gunController.Reload();
        }
    }
Пример #10
0
    void Update()
    {
        Vector3 moveInput    = new Vector3(Input.GetAxisRaw("Horizontal"), 0f, Input.GetAxisRaw("Vertical"));
        Vector3 moveVelocity = moveInput.normalized * moveSpeed;

        controller.Move(moveVelocity);

        Ray   ray         = viewCamera.ScreenPointToRay(Input.mousePosition);
        Plane groundPlane = new Plane(Vector3.up, Vector3.up * gunController.GunHeight);
        float rayDistance;

        if (groundPlane.Raycast(ray, out rayDistance))
        {
            Vector3 point = ray.GetPoint(rayDistance);
            controller.LookAt(point);
            crossHairs.transform.position = point;
            crossHairs.DetectTargets(ray);
            if ((new Vector2(point.x, point.z) - new Vector2(transform.position.x, transform.position.z)).sqrMagnitude > 1f)
            {
                gunController.Aim(point);
            }
        }

        if (Input.GetMouseButton(0))
        {
            gunController.OnTriggerHold();
        }

        if (Input.GetMouseButtonUp(0))
        {
            gunController.OnTriggerRelease();
        }

        if (Input.GetKeyDown(KeyCode.R))
        {
            gunController.Reload();
        }
    }
Пример #11
0
    void Update()
    {
        //Movement
        Vector3 moveInput    = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical"));
        Vector3 moveVelocity = moveInput.normalized * moveSpeed;

        controller.move(moveVelocity);

        //Look
        Ray   ray         = viewCamera.ScreenPointToRay(Input.mousePosition);
        Plane groundPlane = new Plane(Vector3.up, Vector3.up * gunController.GunHeight());
        float rayDistance;

        if (groundPlane.Raycast(ray, out rayDistance))
        {
            Vector3 point = ray.GetPoint(rayDistance);
            //Debug.DrawLine(ray.origin,point,Color.red);
            controller.LookAt(point);
            crosshairs.transform.position = point;
            crosshairs.DetectTargets(ray);
            gunController.Aim(point);
        }

        //Weapon
        if (Input.GetMouseButton(0))
        {
            gunController.OnTriggerHold();
        }
        if (Input.GetMouseButtonUp(0))
        {
            gunController.OnTriggerRelease();
        }
        if (Input.GetKeyDown(KeyCode.R))
        {
            gunController.Reload();
        }
    }
Пример #12
0
    void LookInput()
    {
        //get mouse position/ Return ray from camera through this pos
        Ray ray = viewCamera.ScreenPointToRay(Input.mousePosition);
        //1 - normal, direction
        Plane groundPlane = new Plane(Vector3.up, Vector3.up * gunController.GunHeight);
        float rayDistance;

        if (groundPlane.Raycast(ray, out rayDistance))
        {
            //len from camera to intersection
            Vector3 point = ray.GetPoint(rayDistance);
            // Debug.DrawLine(ray.origin, point,Color.green);
            controller.LookAt(point);
            crosshairs.transform.position = point;
            crosshairs.DetectTargets(ray);
            //distance check for aiming crosshair. if too close - stop aiming
            //sqrMagnitude is faster than magnitude
            if ((new Vector2(point.x, point.z) - new Vector2(transform.position.x, transform.position.z)).sqrMagnitude > 1)
            {
                gunController.aim(point);
            }
        }
    }
Пример #13
0
    void Update()
    {
        // Movement input
        Vector3 moveInput    = new Vector3(joystick.Horizontal() / 10, 0, joystick.Vertical() / 10);
        Vector3 moveVelocity = moveInput.normalized * moveSpeed;

        controller.Move(moveVelocity);

        // Look input
        Ray   ray         = viewCamera.ScreenPointToRay(Input.mousePosition);
        Plane groundPlane = new Plane(Vector3.up, Vector3.up * gunController.GunHeight);
        float rayDistance;

        if (groundPlane.Raycast(ray, out rayDistance))
        {
            Vector3 point = ray.GetPoint(rayDistance);
            //Debug.DrawLine(ray.origin,point,Color.red);
            controller.LookAt(point);              //Done by me --------------------------------------------
            crosshairs.transform.position = point;
            crosshairs.DetectTargets(ray);
        }

        // Weapon input
        if (Input.GetMouseButton(0))
        {
            gunController.OnTriggerHold();
        }
        if (Input.GetMouseButtonUp(0))
        {
            gunController.OnTriggerRelease();
        }
        if (transform.position.y < -10)
        {
            TakeDamage(health);
        }
    }
Пример #14
0
    // Update is called once per frame
    void Update()
    {
        if (this.isDead())
        {
            this.crossHairs.enabled = false;
            return;
        }

        // MOVIMENTA O PERSONAGEM COM AS TECLAS
        Vector3 moveInput    = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical"));
        Vector3 moveVelocity = moveInput.normalized * moveSpeed;

        // TODO AQUI
        controller.Move(moveVelocity);

        // O PERSONAGEM OLHA PARA ONDE O MOUSE ESTIVER
        Ray   ray         = viewCamera.ScreenPointToRay(Input.mousePosition);
        Plane groundPlane = new Plane(Vector3.up, Vector3.up * gunController.GunHeight());
        float rayDistance;

        if (groundPlane.Raycast(ray, out rayDistance))
        {
            Vector3 point = ray.GetPoint(rayDistance);
            Debug.DrawLine(ray.origin, point, Color.red);
            controller.LookAt(point);
            crossHairs.transform.position = point;
            crossHairs.DetectTargets(ray);
        }

        // ATIRAR
        if (Input.GetMouseButton(0))
        {
            gunController.OnTriggerHold();
        }
        if (Input.GetMouseButtonUp(0))
        {
            gunController.OntriggerRelease();
        }
        if (Input.GetKeyDown(KeyCode.R))
        {
            gunController.Reload();
        }
        if (Input.GetKeyDown(KeyCode.E))
        {
            gunController.ChangeFireMod();
        }
        if (Input.GetKeyDown(KeyCode.T))
        {
            gunController.EquipGun(gunNumber++);
        }

        if (transform.position.y < -10)
        {
            TakeDamage(health);
        }

        if (Input.GetKeyDown(KeyCode.Space))
        {
            controller.Jump();
        }
    }
Пример #15
0
    void Update()
    {
        //Movement checks
        _controller.CalculateDirection();
        _controller.SetRotation();

        //PlayerController Input
        _controller.ReadInput();
        _controller.CheckGroundStatus();
        _controller.CheckForTurns();

        //set animations
        _playerAnim.SetBool("IsWalking", _controller.isWalking);
        _playerAnim.SetBool("Running", _controller.isRunning);
        _playerAnim.SetBool("Stopping", _controller.isStopping);
        _playerAnim.SetBool("Moving", _controller.isMoving);
        _playerAnim.SetBool("IsSliding", _controller.isSliding);
        _playerAnim.SetBool("IsDodging", _controller.isDodging);
        _playerAnim.SetBool("IsTurning", _controller.isTurning);
        _playerAnim.SetBool("HasDodged", _controller.hasDodged);
        _playerAnim.SetFloat("WalkVelX", _controller.walkVelocity.x);
        _playerAnim.SetFloat("WalkVelY", _controller.walkVelocity.y);

        //Interactable detection
        _eyes.DetectInteractables(_interactDistance, _outerInteractDistance, _interactables, _maxtargets);
        Vector2    mouseScreenPosition = Input.mousePosition;
        Ray        ray = _viewCamera.ScreenPointToRay(mouseScreenPosition);
        RaycastHit hit;

        if (Input.GetMouseButtonDown(0))
        {
            _controller.CreateRay();
        }

        if (_controller.isLockedOn)
        {
            if (_controller.target != null)
            {
                _gunController.Aim(_controller.target.transform.position);
            }
            else
            {
                _controller.isLockedOn = false;
            }
        }

        if (Physics.Raycast(ray, out hit, _maxRayDistance, _layerMask))
        {
            _point = hit.point;
            _crosshair.DetectTargets(ray);
        }
        else
        {
            _point = ray.origin + ray.direction * _maxRayDistance;
        }
        Debug.DrawLine(ray.origin, _point, Color.red);
        _crosshair.transform.position = _point;
        if ((new Vector3(_point.x, _point.z) - new Vector3(transform.position.x, transform.position.z)).sqrMagnitude > .2f && !_controller.isLockedOn)
        {
            _gunController.Aim(_point);
        }
        //Weapon
        if (Input.GetKey(KeyCode.F))
        {
            _gunController.EquipGun(startingGun);
        }
        if (!_gunController.isReloading && Input.GetKeyDown(KeyCode.R))
        {
            _gunController.Reload();
        }
        if (Input.GetKey(KeyCode.LeftShift))
        {
            _gunController.recoilStrength = 4;
        }
        else
        {
            _gunController.recoilStrength = _gunController.maxRecoil;
        }
        if (Input.GetMouseButton(0))
        {
            _gunController.OnTriggerHold();
        }
        if (Input.GetMouseButtonUp(0))
        {
            _gunController.OnTriggerRelease();
        }

        //Running
        if (_controller.forwardVelocity == 0)
        {
            _controller.isMoving   = false;
            _controller.isStopping = false;
            _controller.isRunning  = false;
        }
        else
        {
            _controller.isMoving = true;
        }

        if (_controller.forwardVelocity <= (_controller.maxSpeed * .5f) && _controller.isRunning)
        {
            _controller.isRunning  = false;
            _controller.isStopping = true;
        }
        //Sliding
        if (_controller.isSliding)
        {
            _controller.Slide();
        }
        //Dodging
        if (_controller.isDodging)
        {
            _controller.Dodge();
        }
    }
Пример #16
0
    void Update()
    {
        // Movement input
        Vector3 moveInput    = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical"));
        Vector3 moveVelocity = moveInput.normalized * moveSpeed;

        controller.Move(moveVelocity);

        // Look input
        Ray   ray         = viewCamera.ScreenPointToRay(Input.mousePosition);
        Plane groundPlane = new Plane(Vector3.up, Vector3.up * gunController.GunHeight);
        float rayDistance;

        if (groundPlane.Raycast(ray, out rayDistance))
        {
            Vector3 point = ray.GetPoint(rayDistance);
            //Debug.DrawLine(ray.origin,point,Color.red);
            controller.LookAt(point);
            crosshairs.transform.position = point;
            crosshairs.DetectTargets(ray);
            if ((new Vector2(point.x, point.z) - new Vector2(transform.position.x, transform.position.z)).sqrMagnitude > 1)
            {
                gunController.Aim(point);
            }
        }

        switch (spawner.currentWaveNumber)
        {
        case 0:
            Debug.Log("current 0");
            break;

        case 1:
            a_weappon_1 = true;
            break;

        case 2:
            a_weappon_2 = true;
            break;

        case 3:
            a_weappon_3 = true;
            break;

        case 4:
            a_weappon_4 = true;
            break;

        case 5:
            a_weappon_5 = true;
            break;
        }


        // Weapon input
        if (Input.GetMouseButton(0))
        {
            gunController.OnTriggerHold();
        }
        if (Input.GetMouseButtonUp(0))
        {
            gunController.OnTriggerRelease();
        }
        if (Input.GetKeyDown(KeyCode.R))
        {
            gunController.Reload();
        }

        if (transform.position.y < -10)
        {
            TakeDamage(health);
        }

        if (a_weappon_1)
        {
            if (Input.GetKeyDown(KeyCode.Alpha1))
            {
                gunController.EquipGun(0);
                Debug.Log("click");
            }

            weapons[0].SetActive(true);
        }

        if (a_weappon_2)
        {
            if (Input.GetKeyDown(KeyCode.Alpha2))
            {
                gunController.EquipGun(1);
            }

            weapons[1].SetActive(true);
        }

        if (a_weappon_3)
        {
            if (Input.GetKeyDown(KeyCode.Alpha3))
            {
                gunController.EquipGun(2);
            }

            weapons[2].SetActive(true);
        }

        if (a_weappon_4)
        {
            if (Input.GetKeyDown(KeyCode.Alpha4))
            {
                gunController.EquipGun(3);
            }

            weapons[3].SetActive(true);
        }

        if (a_weappon_5)
        {
            if (Input.GetKeyDown(KeyCode.Alpha5))
            {
                gunController.EquipGun(4);
            }

            weapons[4].SetActive(true);
        }
    }
Пример #17
0
    void Update()
    {
        // Movement Input
        Vector3 moveInput    = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical"));
        Vector3 MoveVelocity = moveInput.normalized * moveSpeed;

        controller.Move(MoveVelocity);

        // Run Input
        if (Input.GetKey(KeyCode.LeftShift))
        {
            if (grounded)
            {
                moveSpeed = runSpeed;
            }
        }
        // Jump Input
        if (Input.GetButtonDown("Jump"))
        {
            if (grounded)
            {
                GetComponent <Rigidbody> ().AddForce(transform.up * jumpForce);
            }
        }
        grounded = false;
        Ray        _ray = new Ray(transform.position, -transform.up);
        RaycastHit hit;

        if (Physics.Raycast(_ray, out hit, 1 + .1f, groundedMask))
        {
            grounded = true;
        }

        if (Input.GetButtonDown("Jump"))
        {
            if (jumpCounter < maxJumps)
            {
                GetComponent <Rigidbody>().AddForce(transform.up * jumpForce);
                jumpCounter++;
            }
        }

        if (grounded)
        {
            jumpCounter = 1;
        }

        // Look Input
        Ray   ray         = viewCamera.ScreenPointToRay(Input.mousePosition);
        Plane groundPLane = new Plane(Vector3.up, Vector3.zero);
        float rayDistance;

        if (groundPLane.Raycast(ray, out rayDistance))
        {
            Vector3 point = ray.GetPoint(rayDistance);
            //Debug.DrawLine(ray.origin,point,Color.black);
            controller.LookAt(point);
            crosshairs.transform.position = point;
            crosshairs.DetectTargets(ray);
        }
        // Weapon Input
        if (Input.GetMouseButton(0))
        {
            gunController.OnTriggerHold();
        }

        if (Input.GetMouseButtonUp(0))
        {
            gunController.OnTriggerRelease();
        }

        if (transform.position.y < -10)
        {
            TakeDamage(health);
        }
    }
Пример #18
0
    // Update is called once per frame
    void Update()
    {
        //Move input
        moveInput    = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical"));
        moveVelocity = moveInput.normalized * movespeed;
        controller.Move(moveVelocity);
        ray = viewCamera.ScreenPointToRay(Input.mousePosition);
        Plane groundPlane = new Plane(Vector3.up, Vector3.up * gunContorller.GunHeight);

        if (moveInput.x < 0)
        {
            spriteRenderer.flipX = true;
        }
        else if (moveInput.x > 0)
        {
            spriteRenderer.flipX = false;
        }
        //LookAt input
        float rayDistance;

        if (groundPlane.Raycast(ray, out rayDistance))
        {
            Vector3 point = ray.GetPoint(rayDistance);
            // controller.LookAt(point);
            crosshairs.transform.position = point;
            crosshairs.DetectTargets(ray);
            if ((new Vector2(point.x, point.z) - new Vector2(transform.position.x, transform.position.z)).magnitude > 1)
            {
                gunContorller.Aim(point);
            }
        }

        //Weapon input
        if (Input.GetMouseButton(0))
        {
            gunContorller.OnTriggerHold();
        }
        if (Input.GetMouseButtonUp(0))
        {
            gunContorller.OnTriggerRelease();
        }
        if (Input.GetKeyDown(KeyCode.R))
        {
            gunContorller.Reload();
        }
        if (transform.position.y < -10f)
        {
            TakeDamage(health);
        }
        if (ContextHelper.playerMood <= 0)
        {
            Die();
        }

        if (Input.GetKeyDown(KeyCode.F))
        {
            if (gunContorller.allGun.Length > gunIndex)
            {
                gunContorller.EquipGun(gunIndex++);
            }
            else
            {
                gunIndex = 0;
            }
        }
    }
Пример #19
0
    // Update is called once per frame
    void Update()
    {
        float m_horizontal;
        float m_vertical;

        float r_horizontal;
        float r_vertical;

        // Floating Joystick Input
        if (androidController)
        {
            // Joystick Movement Input
            m_horizontal = movementJoystick.Horizontal;
            m_vertical   = movementJoystick.Vertical;

            //m_horizontal = Input.GetAxisRaw("Horizontal");
            //m_vertical = Input.GetAxisRaw("Vertical");

            r_horizontal = rotationJoystick.Horizontal;
            r_vertical   = rotationJoystick.Vertical;

            // Animate Joystick Look
            if (camT != null)
            {
                camForward = Vector3.Scale(camT.up, new Vector3(1, 0, 1)).normalized;
                move       = m_vertical * camForward + m_horizontal * camT.right;
            }
            else
            {
                move = m_vertical * Vector3.forward + m_horizontal * Vector3.right;
            }

            if (move.magnitude > 1)
            {
                move.Normalize();
            }
            Move(move);

            // Joystick Look Input
            Vector3 rotationInput = new Vector3(r_horizontal, 0, r_vertical);
            if (rotationInput != Vector3.zero)
            {
                targetRotation = Quaternion.LookRotation(rotationInput);
            }
            transform.rotation = Quaternion.RotateTowards(transform.rotation, targetRotation, lookSpeed);
        }
        else
        {
            m_horizontal = Input.GetAxisRaw("Horizontal");
            m_vertical   = Input.GetAxisRaw("Vertical");

            // Animate Mouse Look
            if (camT != null)
            {
                camForward = Vector3.Scale(camT.up, new Vector3(1, 0, 1)).normalized;
                move       = m_vertical * camForward + m_horizontal * camT.right;
            }
            else
            {
                move = m_vertical * Vector3.forward + m_horizontal * Vector3.right;
            }

            if (move.magnitude > 1)
            {
                move.Normalize();
            }
            Move(move);

            // Look Input
            Ray   ray         = viewCamera.ScreenPointToRay(Input.mousePosition);
            Plane groundPlane = new Plane(Vector3.up, Vector3.up * gunController.GunHeight);
            float rayDistance;

            if (groundPlane.Raycast(ray, out rayDistance))
            {
                Vector3 point = ray.GetPoint(rayDistance);
                //Debug.DrawLine(ray.origin, point, Color.red);
                controller.LookAt(point);
                crosshairs.transform.position = point;
                crosshairs.DetectTargets(ray);
                if ((new Vector2(point.x, point.z) - new Vector2(transform.position.x, transform.position.z)).sqrMagnitude > 1)
                {
                    gunController.Aim(point);
                }
            }
        }

        // Jump Input
        if (Input.GetButtonDown("Jump"))
        {
            if (isGrounded)
            {
                anim.SetTrigger("Jump");
                isGrounded = false;
            }
            else
            {
                isGrounded = true;
            }
        }

        // Fire
        if (monsterInfoUI.gameObject.activeSelf != true)
        {
            if (fireButton.Pressed && androidController == true)
            {
                gunController.OnTriggerHold();
            }
            else if (Input.GetKey(KeyCode.Mouse0) && androidController == false)
            {
                gunController.OnTriggerHold();
            }
            else
            {
                gunController.OnTriggerRelease();
            }

            if (Input.GetKeyDown(KeyCode.R))
            {
                gunController.Reload();
            }
        }

        //Falling
        if (transform.position.y < -10)
        {
            TakeDamage(health);
        }

        // Movement Input
        Vector3 moveInput    = new Vector3(m_horizontal, 0, m_vertical);
        Vector3 moveVelocity = moveInput.normalized * moveSpeed;

        moveDir = moveVelocity;
        controller.Move(moveVelocity);

        // Dashing
        if (Input.GetKeyDown(KeyCode.Space))
        {
            Dash();
        }
        if (currentDashTime < maxDashTime)
        {
            isDashing = true;
            controller.Move(moveDir * dashSpeed);
            currentDashTime += dashStoppingSpeed;
        }
        else
        {
            isDashing = false;
            //Debug.Log("Nothing");
            GetComponent <TrailRenderer>().enabled = false;
        }

        if (dashLimit == 0)
        {
            StartCoroutine("resetDashLimit");
            //Debug.Log(dashLimit);
        }
        else if (dashLimit == maxDashLimit)
        {
            StopCoroutine("resetDashLimit");
        }
    }