Esempio n. 1
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();
        }
    }