Exemple #1
0
    public virtual void UpdateGun()
    {
        if (HideGunWhileZooming && FPSmotor && NormalCamera.GetComponent <Camera> ().enabled)
        {
            FPSmotor.HideGun(!Zooming);
        }

        if (animation || !Active)
        {
            return;
        }

        switch (gunState)
        {
        case 0:
            // Start Bolt
            if (AmmoIn <= 0)
            {
                // Check Ammo in clip
                if (Clip > 0)
                {
                    animation.clip = animation [BoltPose].clip;
                    animation.CrossFade(BoltPose, 0.5f, PlayMode.StopAll);
                    gunState = 2;
                    // scope rotation a bit when reloading
                    if (FPSmotor && Zooming)
                    {
                        FPSmotor.CameraForceRotation(new Vector3(0, 0, 20));
                        FPSmotor.Stun(0.2f);
                    }
                    if (SoundBoltStart && audiosource != null)
                    {
                        audiosource.PlayOneShot(SoundBoltStart);
                    }
                    Clip -= 1;
                }
                else
                {
                    gunState = 3;
                }
            }
            break;

        case 1:
            // Countdown to idle state
            if (Time.time >= cooldowntime + CooldownTime)
            {
                gunState = 0;
            }
            break;

        case 2:
            animation.Play();
            // finish bold animation
            if (animation [BoltPose].normalizedTime > BoltTime)
            {
                if (Shell && ShellSpawn)
                {
                    if (!boltout)
                    {
                        GameObject shell         = (GameObject)Instantiate(Shell, ShellSpawn.position, ShellSpawn.rotation);
                        Rigidbody  shelrigidbody = shell.GetComponent <Rigidbody> ();
                        shelrigidbody.AddForce(ShellSpawn.transform.right * 2);
                        shelrigidbody.AddTorque(Random.rotation.eulerAngles * 10);
                        GameObject.Destroy(shell, 5);
                        boltout = true;
                        if (FPSmotor && Zooming)
                        {
                            FPSmotor.CameraForceRotation(new Vector3(0, 0, -5));
                            FPSmotor.Stun(0.1f);
                        }
                    }
                }
            }
            if (animation [BoltPose].normalizedTime > 0.9f)
            {
                gunState = 0;
                AmmoIn   = 1;
                animation.CrossFade(IdlePose);
                if (SoundBoltEnd && audiosource != null)
                {
                    audiosource.PlayOneShot(SoundBoltEnd);
                }
            }
            break;

        case 3:
            // Start Reloading
            if (animation [ReloadPose] && (AmmoPack > 0 || InfinityAmmo))
            {
                animation.clip = animation [ReloadPose].clip;
                animation.CrossFade(ReloadPose, 0.5f, PlayMode.StopAll);
                gunState = 4;
                Zooming  = false;
                if (SoundReloadStart && audiosource != null)
                {
                    audiosource.PlayOneShot(SoundReloadStart);
                }
            }
            else
            {
                gunState = 0;
            }
            break;

        case 4:

            if (animation [ReloadPose])
            {
                if (animation.clip.name != animation [ReloadPose].name)
                {
                    animation.clip = animation [ReloadPose].clip;
                    animation.CrossFade(ReloadPose, 0.5f, PlayMode.StopAll);
                }
                if (animation [ReloadPose].normalizedTime > 0.8f)
                {
                    gunState = 0;
                    if (InfinityAmmo)
                    {
                        Clip = ClipSize;
                    }
                    else
                    {
                        if (AmmoPack >= ClipSize)
                        {
                            Clip      = ClipSize;
                            AmmoPack -= ClipSize;
                        }
                        else
                        {
                            Clip     = AmmoPack;
                            AmmoPack = 0;
                        }
                    }

                    if (Clip > 0)
                    {
                        animation.CrossFade(IdlePose);
                        if (SoundReloadEnd && audiosource != null)
                        {
                            audiosource.PlayOneShot(SoundReloadEnd);
                        }
                    }
                }
            }
            else
            {
                gunState = 0;
            }
            break;
        }

        if (FPSmotor)
        {
            if (Zooming)
            {
                FPSmotor.sensitivityXMult = MouseSensitiveZoom;
                FPSmotor.sensitivityYMult = MouseSensitiveZoom;
                FPSmotor.Noise            = true;
            }
            else
            {
                FPSmotor.sensitivityXMult = MouseSensitive;
                FPSmotor.sensitivityYMult = MouseSensitive;
                FPSmotor.Noise            = false;
            }
        }

        if (Zooming)
        {
            if (ZoomFOVLists.Length > 0)
            {
                MouseSensitiveZoom        = ((MouseSensitive * 0.16f) / 10) * ZoomFOVLists [IndexZoom];
                NormalCamera.fieldOfView += (ZoomFOVLists [IndexZoom] - NormalCamera.fieldOfView) / 10;
            }
        }
        else
        {
            NormalCamera.fieldOfView += (fovTemp - NormalCamera.fieldOfView) / 10;
        }

        if (audiosource != null)
        {
            audiosource.pitch = Time.timeScale;
            if (audiosource.pitch < 0.5f)
            {
                audiosource.pitch = 0.5f;
            }
        }
    }