Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        ComArduino comArdu = GameObject.Find("Com").GetComponent <ComArduino>();

        //UN EJE
        // transform.position = new Vector3(comArdu.imu_x,0,0);
        //Pospistola = transform.eulerAngles;

        //DOS EJES SIN OFFSETS
        //transform.localRotation.eulerAngles = new Vector3(comArdu.imu_y, 0f, comArdu.imu_x);

        //DOS EJES CON OFFSET Y SIN LOCAL
        //giroZ = comArdu.imu_x*(-1);
        //transform.eulerAngles = new Vector3(comArdu.imu_y - 100, 0f, giroZ);

        //DOS EJES CON OFFSET CON LOCAL
        //giroZ = comArdu.imu_x*(-1);
        //transform.localEulerAngles = new Vector3(comArdu.imu_y - 100, 0f, giroZ);

        //DOS EJES LOCAL Y REFERENCIA INICIAL
        giroZ = comArdu.imu_x * (1);

        transform.localEulerAngles = new Vector3(comArdu.imu_y - imu_origin.y + 15 /*- 90*/, giroZ - imu_origin.z + 180.0f, 0f);

        //CALIBRANDO
        //transform.localEulerAngles = new Vector3(comArdu.imu_y - imu_origin.y /*- 90*/, comArdu.imu_x-imu_origin.x,0f-180);
        Pospistola = transform.eulerAngles;
    }
Ejemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        ComArduino comArdu = GameObject.Find("Com").GetComponent <ComArduino>();

        // transform.position = new Vector3(comArdu.imu_x,0,0);
        transform.eulerAngles = new Vector3(0f, comArdu.imu_x, 0f);
        Poscubo = transform.eulerAngles;
    }
Ejemplo n.º 3
0
    void Start()
    {
        ComArduino comArdu = GameObject.Find("Com").GetComponent <ComArduino>();

        //PARA CALIBRAR LEER EL TRIGGER

        imu_origin.x = comArdu.imu_x;
        imu_origin.y = comArdu.imu_x;
        imu_origin.z = comArdu.imu_y;
    }
Ejemplo n.º 4
0
        /// Initializes the FpsController on start.
        private void Start()
        {
            _rigidbody             = GetComponent <Rigidbody>();
            _rigidbody.constraints = RigidbodyConstraints.FreezeRotation;
            _collider         = GetComponent <CapsuleCollider>();
            _audioSource      = GetComponent <AudioSource>();
            arms              = AssignCharactersCamera();
            _audioSource.clip = walkingSound;
            _audioSource.loop = true;
            _rotationX        = new SmoothRotation(RotationXRaw);
            _rotationY        = new SmoothRotation(RotationYRaw);
            _velocityX        = new SmoothVelocity();
            _velocityZ        = new SmoothVelocity();
            Cursor.lockState  = CursorLockMode.Locked;
            ValidateRotationRestriction();

            //AÑADIDO POR MONCHE
            ComArduino comArdu = GameObject.Find("Com").GetComponent <ComArduino>();

            imu_origin.x = comArdu.imu_x;
            imu_origin.y = 0f;
            imu_origin.z = comArdu.imu_y;
        }
Ejemplo n.º 5
0
    private void Update()
    {
        //Aiming
        //Toggle camera FOV when right click is held down

        /***************MONCHEFICADO***************/

        //if(Input.GetButton("Fire2") && !isReloading && !isRunning && !isInspecting)
        ComArduino comArdu = GameObject.Find("Com").GetComponent <ComArduino>();

        //if((comArdu.trigg==1) && !isReloading && !isRunning && !isInspecting)
        if ((1 == 1) && !isReloading && !isRunning && !isInspecting)
        /***************MONCHEFICADO***************/

        {
            gunCamera.fieldOfView = Mathf.Lerp(gunCamera.fieldOfView,
                                               aimFov, fovSpeed * Time.deltaTime);

            isAiming = true;

            anim.SetBool("Aim", true);

            if (!soundHasPlayed)
            {
                mainAudioSource.clip = SoundClips.aimSound;
                mainAudioSource.Play();

                soundHasPlayed = true;
            }
        }
        else
        {
            //When right click is released
            gunCamera.fieldOfView = Mathf.Lerp(gunCamera.fieldOfView,
                                               defaultFov, fovSpeed * Time.deltaTime);

            isAiming = false;

            anim.SetBool("Aim", false);
        }
        //Aiming end

        //If randomize muzzleflash is true, genereate random int values
        if (randomMuzzleflash == true)
        {
            randomMuzzleflashValue = Random.Range(minRandomValue, maxRandomValue);
        }

        //Timescale settings
        //Change timescale to normal when 1 key is pressed
        if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            Time.timeScale     = 1.0f;
            timescaleText.text = "1.0";
        }
        //Change timescale to 50% when 2 key is pressed
        if (Input.GetKeyDown(KeyCode.Alpha2))
        {
            Time.timeScale     = 0.5f;
            timescaleText.text = "0.5";
        }
        //Change timescale to 25% when 3 key is pressed
        if (Input.GetKeyDown(KeyCode.Alpha3))
        {
            Time.timeScale     = 0.25f;
            timescaleText.text = "0.25";
        }
        //Change timescale to 10% when 4 key is pressed
        if (Input.GetKeyDown(KeyCode.Alpha4))
        {
            Time.timeScale     = 0.1f;
            timescaleText.text = "0.1";
        }
        //Pause game when 5 key is pressed
        if (Input.GetKeyDown(KeyCode.Alpha5))
        {
            Time.timeScale     = 0.0f;
            timescaleText.text = "0.0";
        }

        //Set current ammo text from ammo int
        currentAmmoText.text = currentAmmo.ToString();

        //Continosuly check which animation
        //is currently playing
        AnimationCheck();

        //Play knife attack 1 animation when Q key is pressed
        if (Input.GetKeyDown(KeyCode.Q) && !isInspecting)
        {
            anim.Play("Knife Attack 1", 0, 0f);
        }
        //Play knife attack 2 animation when F key is pressed
        if (Input.GetKeyDown(KeyCode.F) && !isInspecting)
        {
            anim.Play("Knife Attack 2", 0, 0f);
        }

        //Throw grenade when pressing G key
        if (Input.GetKeyDown(KeyCode.G) && !isInspecting)
        {
            StartCoroutine(GrenadeSpawnDelay());
            //Play grenade throw animation
            anim.Play("GrenadeThrow", 0, 0.0f);
        }

        //If out of ammo
        if (currentAmmo == 0)
        {
            //Show out of ammo text
            currentWeaponText.text = "OUT OF AMMO";
            //Toggle bool
            outOfAmmo = true;
            //Auto reload if true
            if (autoReload == true && !isReloading)
            {
                StartCoroutine(AutoReload());
            }

            //Set slider back
            anim.SetBool("Out Of Ammo Slider", true);
            //Increase layer weight for blending to slider back pose
            anim.SetLayerWeight(1, 1.0f);
        }
        else
        {
            //When ammo is full, show weapon name again
            currentWeaponText.text = storedWeaponName.ToString();
            //Toggle bool
            outOfAmmo = false;
            //anim.SetBool ("Out Of Ammo", false);
            anim.SetLayerWeight(1, 0.0f);
        }

        //Shooting
        /******************MONCHEFICADO**************************/

        //if (Input.GetMouseButtonDown (0) && !outOfAmmo && !isReloading && !isInspecting && !isRunning)
        if ((comArdu.trigg == 1) && !outOfAmmo && !isReloading && !isInspecting && !isRunning)

        /******************MONCHEFICADO**************************/
        {
            anim.Play("Fire", 0, 0f);

            muzzleParticles.Emit(1);

            //Remove 1 bullet from ammo
            //currentAmmo -= 1;					//////////////////////////////////////////////////////////////////////////////////
            currentAmmo -= 0;


            RaycastHit hit;

/************************MONCHEFICADO**************************/

//Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            Ray ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width * 0.5f, Screen.height * 0.5f, 0f));
/************************MONCHEFICADO**************************/

            if (Physics.Raycast(ray, out hit, 1000.0f))
            {
                if (hit.transform.CompareTag("Enemy"))
                {
                    EnemyController enemy = hit.transform.GetComponent <EnemyController>();
                    enemy.TakeDamage(damage);
                }
                if (hit.collider.tag == "Fondo")
                {
                    Puntuacion.combo = 1;
                }
                if (hit.collider.isTrigger)
                {
                    Puntuacion.extra = 50;
                    //source.PlayOneShot(HeadShot, 20F);
                    //Debug.Log("Cabeza funciona");
                }
                else
                {
                    Puntuacion.extra = 0;
                }
            }

            //////////////////////////////////////////////////////////////////////////////////////////

            shootAudioSource.clip = SoundClips.shootSound;
            shootAudioSource.Play();

            //Light flash start
            StartCoroutine(MuzzleFlashLight());

            if (!isAiming)             //if not aiming
            {
                anim.Play("Fire", 0, 0f);

                muzzleParticles.Emit(1);

                if (enableSparks == true)
                {
                    //Emit random amount of spark particles
                    sparkParticles.Emit(Random.Range(1, 6));
                }
            }
            else             //if aiming
            {
                anim.Play("Aim Fire", 0, 0f);

                //If random muzzle is false
                if (!randomMuzzleflash)
                {
                    muzzleParticles.Emit(1);
                    //If random muzzle is true
                }
                else if (randomMuzzleflash == true)
                {
                    //Only emit if random value is 1
                    if (randomMuzzleflashValue == 1)
                    {
                        if (enableSparks == true)
                        {
                            //Emit random amount of spark particles
                            sparkParticles.Emit(Random.Range(1, 6));
                        }
                        if (enableMuzzleflash == true)
                        {
                            muzzleParticles.Emit(1);
                            //Light flash start
                            StartCoroutine(MuzzleFlashLight());
                        }
                    }
                }
            }

            //Spawn bullet at bullet spawnpoint
            var bullet = (Transform)Instantiate(
                Prefabs.bulletPrefab,
                Spawnpoints.bulletSpawnPoint.transform.position,
                Spawnpoints.bulletSpawnPoint.transform.rotation);

            //Add velocity to the bullet
            bullet.GetComponent <Rigidbody>().velocity =
                bullet.transform.forward * bulletForce;

            //Spawn casing prefab at spawnpoint
            Instantiate(Prefabs.casingPrefab,
                        Spawnpoints.casingSpawnPoint.transform.position,
                        Spawnpoints.casingSpawnPoint.transform.rotation);
        }

        //Inspect weapon when pressing T key
        if (Input.GetKeyDown(KeyCode.T))
        {
            anim.SetTrigger("Inspect");
        }

        //Toggle weapon holster when pressing E key
        if (Input.GetKeyDown(KeyCode.E) && !hasBeenHolstered)
        {
            holstered = true;

            mainAudioSource.clip = SoundClips.holsterSound;
            mainAudioSource.Play();

            hasBeenHolstered = true;
        }
        else if (Input.GetKeyDown(KeyCode.E) && hasBeenHolstered)
        {
            holstered = false;

            mainAudioSource.clip = SoundClips.takeOutSound;
            mainAudioSource.Play();

            hasBeenHolstered = false;
        }

        //Holster anim toggle
        if (holstered == true)
        {
            anim.SetBool("Holster", true);
        }
        else
        {
            anim.SetBool("Holster", false);
        }

        //Reload
        if (Input.GetKeyDown(KeyCode.R) && !isReloading && !isInspecting)
        {
            //Reload
            Reload();

            if (!hasStartedSliderBack)
            {
                hasStartedSliderBack = true;
                StartCoroutine(HandgunSliderBackDelay());
            }
        }

        //Walking when pressing down WASD keys
        if (Input.GetKey(KeyCode.W) && !isRunning ||
            Input.GetKey(KeyCode.A) && !isRunning ||
            Input.GetKey(KeyCode.S) && !isRunning ||
            Input.GetKey(KeyCode.D) && !isRunning)
        {
            anim.SetBool("Walk", true);
        }
        else
        {
            anim.SetBool("Walk", false);
        }

        //Running when pressing down W and Left Shift key
        if ((Input.GetKey(KeyCode.W) && Input.GetKey(KeyCode.LeftShift)))
        {
            isRunning = true;
        }
        else
        {
            isRunning = false;
        }

        //Run anim toggle
        if (isRunning == true)
        {
            anim.SetBool("Run", true);
        }
        else
        {
            anim.SetBool("Run", false);
        }
    }