0
\$\begingroup\$

I'm following this video: How to make a Sniper Scope Effect - Unity FPS Tutorial

Everything in this script works, however when I right-click (to scope in) the fov seems to change for a fraction of a second and then change back to normal. In the video, the guy has the same script and doesn't have a problem.

my script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class scopeManager : MonoBehaviour
{
    public Animator animator;

    public GameObject scopeOverlay;
    public GameObject WeaponCamera;
    public Camera mainCamera;

    public float scopedFOV = 15f;
    private float normalFOV;

    private bool isScoped = false;

    private void Update()
    {
        if (Input.GetButtonDown("Fire2"))
        {
            isScoped = !isScoped;
            animator.SetBool("Scoped", isScoped);

            if (isScoped)
                StartCoroutine(onScoped());
            else
                onUnScoped();                
        }
    }

    void onUnScoped()
    {
        scopeOverlay.SetActive(false);
        WeaponCamera.SetActive(true);

        mainCamera.fieldOfView = normalFOV;
    }

    IEnumerator onScoped ()
    {
        yield return new WaitForSeconds(.15f);

        scopeOverlay.SetActive(true);
        WeaponCamera.SetActive(false);

        normalFOV = mainCamera.fieldOfView;
        mainCamera.fieldOfView = scopedFOV;
    }
}
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.