My code for aim-down-sights using new Starter Assets

I have been using the Unity Starter Assets - First Person Character Controller in my project because the one in the tutorial has been deprecated. Just showing my code with the proper adaptations made for it to work with the modern one.

Just need to access the FirstPersonController script on the player capsule, use the StarterAssests namespace, and change the RotationSpeed variable.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Cinemachine;
using StarterAssets;

public class WeaponZoom : MonoBehaviour
{
    [SerializeField] public CinemachineVirtualCamera fovCamera;
    [SerializeField] float zoomedOutFOV = 60f;
    [SerializeField] float zoomedInFOV = 20f;
    [SerializeField] float zoomOutSensitivity = 2f;
    [SerializeField] float zoomInSensitivity = 1f;

    FirstPersonController fpsController;

    bool zoomedInToggle = false;

    private void Start()
    {
        fpsController = GetComponent<FirstPersonController>();
    }

    private void Update()
    {
        if(Input.GetMouseButtonDown(1))
        {
            if (zoomedInToggle == false)
            {
                zoomedInToggle = true;
                fovCamera.m_Lens.FieldOfView = zoomedInFOV;
                fpsController.RotationSpeed = zoomInSensitivity;
            }
            else
            {
                zoomedInToggle = false;
                fovCamera.m_Lens.FieldOfView = zoomedOutFOV;
                fpsController.RotationSpeed = zoomOutSensitivity;
            }
        }
    }
}

2 Likes

Awesome job!

I have the same issue, but I can’t seem to solve it with your method, because on my end, it does not recognize StandarAssets. I have this code:
using Cinemachine;

using StandardAssets;

// using UnityStandardAssets.Characters.FirstPerson;

public class WeaponZoom : MonoBehaviour

{

[SerializeField] public CinemachineVirtualCamera fovCamera;

So, are you using the Starter Assets - First Person Character Controller | URP asset pack yes?

Since the file Rick was using was deprecated, I downloaded another StandardAssets from a topic solution below the video. Thus, I cannot find the package I am using in the Package Manager list.

I searched the StandardAssets folder for a readme or changlog, but I cannot find a version of it.

But I am using Standard Assets, not Starter Assets
FolderScreenshot

Well, I’m using this asset pack, which is different than the standard asset pack that rick uses. It’s basically the new version.
https://assetstore.unity.com/packages/essentials/starter-assets-first-person-character-controller-urp-196525

Privacy & Terms