Search Unity

FPS Controller and Standard Assets - script error

Discussion in 'Editor & General Support' started by odbdl, Apr 16, 2020.

  1. odbdl

    odbdl

    Joined:
    Apr 16, 2020
    Posts:
    1
    Very sorry if this question is not in the right category:
    I'm a beginner using Standard Assets, Unity 2020. Tried using the FPSController (prefab) but keep getting Script error: "associated script cannot be loaded. Fix any compile errors,.."
    I'm seeing this is a standard issue but did not find the solution.
    Thank you for your help.
     
    rithamsethi likes this.
  2. Deleted User

    Deleted User

    Guest

    In the status bar (at the bottom of the editor) you will also find the line where the error occurs, tell me the line i tell you whats wrong
     
  3. lord_indigo

    lord_indigo

    Joined:
    May 3, 2020
    Posts:
    1
    Did you ever solved this issue?
    I have the same problem. Which version do you use?
     
  4. Tatertot_Tango

    Tatertot_Tango

    Joined:
    Jun 7, 2020
    Posts:
    1
    I am having the same issue. I am new as well... This is the message i get..

    Assets\Standard Assets\Utility\SimpleActivatorMenu.cs(11,16): error CS0619: 'GUIText' is obsolete: 'GUIText has been removed. Use UI.Text instead.'
     
  5. zombies8keagan

    zombies8keagan

    Joined:
    Mar 31, 2020
    Posts:
    1
    I'm having the same issue (also pretty new to this). When I load the script into Visual Studio there are no errors or warnings displayed.

    There are 4 messages though:
    IDE0051 Private member 'FirstPersonController.m_YRotation' is unused.
    IDE0044 Make field Readonly
    IDE0018 Variable declaration can be inlined
    IDE0018 Variable declaration can be inlined
     
  6. charlesb_rm

    charlesb_rm

    Joined:
    Jan 18, 2017
    Posts:
    485
    Hi odbdl, if you're a beginner, you should start with a LTS version of Unity. For example, 2019.4 or 2018.4. Unity 2020.1 is in beta and 2020.2 is in alpha.
     
    puzzledpenguin2 likes this.
  7. willgoldstone

    willgoldstone

    Unity Technologies

    Joined:
    Oct 2, 2006
    Posts:
    794
    Hi @odbdl can you confirm which standard assets you're talking about? I believe you're talking about the 2017 edition on the asset store, in which case comment out line 6 of 'ForcedReset.cs' -

    https://gyazo.com/a4d4a313eee2794a7450130dce63f26e

    And lines 10,21, 35 of 'SimpleActivatorMenu.cs' -

    https://gyazo.com/505d28931e9ae577054bc57bb22bda2e

    That'll get you back up and running with those assets in Unity 2020.1. Note this breaks the use of some of the menus in demo scenes but not the prefabs themselves.

    I also recommend you instead take a look at the more recent 2019 Standard Assets we shared here via github -

    https://github.com/Unity-Technologies/Standard-Assets-Characters

    These are still in beta and currently being reworked by our education team who took over the project in December, BUT they do work just fine in 2020.1 Beta 12 (just checked) - just download the zip, open with that version and let unity do the upgrade when it asks.
     
  8. royamlan

    royamlan

    Joined:
    Jul 13, 2020
    Posts:
    1
    THANKS . THIS WORKED
     
  9. Dalexw

    Dalexw

    Joined:
    Feb 23, 2021
    Posts:
    1
    Many Thanks, this works perfectly. Glad I found this thread.
     
    BattleGr likes this.
  10. BattleGr

    BattleGr

    Joined:
    Sep 13, 2020
    Posts:
    1
    FirstPersonController script ERROR:

    Please Help assets/standard assets/characters/first person/scripts/firstpersonControls.cs(4,27): error CS1001: identifier expected

    ---------------------------------------------------------------------------------------------------------------------------------------------------------

    using System;
    using UnityEngine;
    using UnityStandardAssets;
    using UnityStandardAssets.;
    using Random = UnityEngine.Random;

    #pragma warning disable 618, 649
    namespace UnityStandardAssets.Characters.FirstPerson
    {
    [RequireComponent(typeof (CharacterController))]
    [RequireComponent(typeof (AudioSource))]
    public class FirstPersonController : MonoBehaviour
    {
    [SerializeField] private bool m_IsWalking;
    [SerializeField] private float m_WalkSpeed;
    [SerializeField] private float m_RunSpeed;
    [SerializeField] [Range(0f, 1f)] private float m_RunstepLenghten;
    [SerializeField] private float m_JumpSpeed;
    [SerializeField] private float m_StickToGroundForce;
    [SerializeField] private float m_GravityMultiplier;
    [SerializeField] private MouseLook m_MouseLook;
    [SerializeField] private bool m_UseFovKick;
    [SerializeField] private FOVKick m_FovKick = new FOVKick();
    [SerializeField] private bool m_UseHeadBob;
    [SerializeField] private CurveControlledBob m_HeadBob = new CurveControlledBob();
    [SerializeField] private LerpControlledBob m_JumpBob = new LerpControlledBob();
    [SerializeField] private float m_StepInterval;
    [SerializeField] private AudioClip[] m_FootstepSounds; // an array of footstep sounds that will be randomly selected from.
    [SerializeField] private AudioClip m_JumpSound; // the sound played when character leaves the ground.
    [SerializeField] private AudioClip m_LandSound; // the sound played when character touches back on ground.


    private Camera m_Camera;
    private bool m_Jump;
    private float m_YRotation;
    private Vector2 m_Input;
    private Vector3 m_MoveDir = Vector3.zero;
    private CharacterController m_CharacterController;
    private CollisionFlags m_CollisionFlags;
    private bool m_PreviouslyGrounded;
    private Vector3 m_OriginalCameraPosition;
    private float m_StepCycle;
    private float m_NextStep;
    private bool m_Jumping;
    private AudioSource m_AudioSource;

    // Use this for initialization
    private void Start()
    {
    m_CharacterController = GetComponent<CharacterController>();
    m_Camera = Camera.main;
    m_OriginalCameraPosition = m_Camera.transform.localPosition;
    m_FovKick.Setup(m_Camera);
    m_HeadBob.Setup(m_Camera, m_StepInterval);
    m_StepCycle = 0f;
    m_NextStep = m_StepCycle/2f;
    m_Jumping = false;
    m_AudioSource = GetComponent<AudioSource>();
    m_MouseLook.Init(transform , m_Camera.transform);
    }


    // Update is called once per frame
    private void Update()
    {
    RotateView();
    // the jump state needs to read here to make sure it is not missed
    if (!m_Jump)
    {
    m_Jump = CrossPlatformInputManager.GetButtonDown("Jump");
    }

    if (!m_PreviouslyGrounded && m_CharacterController.isGrounded)
    {
    StartCoroutine(m_JumpBob.DoBobCycle());
    PlayLandingSound();
    m_MoveDir.y = 0f;
    m_Jumping = false;
    }
    if (!m_CharacterController.isGrounded && !m_Jumping && m_PreviouslyGrounded)
    {
    m_MoveDir.y = 0f;
    }

    m_PreviouslyGrounded = m_CharacterController.isGrounded;
    }


    private void PlayLandingSound()
    {
    m_AudioSource.clip = m_LandSound;
    m_AudioSource.Play();
    m_NextStep = m_StepCycle + .5f;
    }


    private void FixedUpdate()
    {
    float speed;
    GetInput(out speed);
    // always move along the camera forward as it is the direction that it being aimed at
    Vector3 desiredMove = transform.forward*m_Input.y + transform.right*m_Input.x;

    // get a normal for the surface that is being touched to move along it
    RaycastHit hitInfo;
    Physics.SphereCast(transform.position, m_CharacterController.radius, Vector3.down, out hitInfo,
    m_CharacterController.height/2f, Physics.AllLayers, QueryTriggerInteraction.Ignore);
    desiredMove = Vector3.ProjectOnPlane(desiredMove, hitInfo.normal).normalized;

    m_MoveDir.x = desiredMove.x*speed;
    m_MoveDir.z = desiredMove.z*speed;


    if (m_CharacterController.isGrounded)
    {
    m_MoveDir.y = -m_StickToGroundForce;

    if (m_Jump)
    {
    m_MoveDir.y = m_JumpSpeed;
    PlayJumpSound();
    m_Jump = false;
    m_Jumping = true;
    }
    }
    else
    {
    m_MoveDir += Physics.gravity*m_GravityMultiplier*Time.fixedDeltaTime;
    }
    m_CollisionFlags = m_CharacterController.Move(m_MoveDir*Time.fixedDeltaTime);

    ProgressStepCycle(speed);
    UpdateCameraPosition(speed);

    m_MouseLook.UpdateCursorLock();
    }


    private void PlayJumpSound()
    {
    m_AudioSource.clip = m_JumpSound;
    m_AudioSource.Play();
    }


    private void ProgressStepCycle(float speed)
    {
    if (m_CharacterController.velocity.sqrMagnitude > 0 && (m_Input.x != 0 || m_Input.y != 0))
    {
    m_StepCycle += (m_CharacterController.velocity.magnitude + (speed*(m_IsWalking ? 1f : m_RunstepLenghten)))*
    Time.fixedDeltaTime;
    }

    if (!(m_StepCycle > m_NextStep))
    {
    return;
    }

    m_NextStep = m_StepCycle + m_StepInterval;

    PlayFootStepAudio();
    }


    private void PlayFootStepAudio()
    {
    if (!m_CharacterController.isGrounded)
    {
    return;
    }
    // pick & play a random footstep sound from the array,
    // excluding sound at index 0
    int n = Random.Range(1, m_FootstepSounds.Length);
    m_AudioSource.clip = m_FootstepSounds[n];
    m_AudioSource.PlayOneShot(m_AudioSource.clip);
    // move picked sound to index 0 so it's not picked next time
    m_FootstepSounds[n] = m_FootstepSounds[0];
    m_FootstepSounds[0] = m_AudioSource.clip;
    }


    private void UpdateCameraPosition(float speed)
    {
    Vector3 newCameraPosition;
    if (!m_UseHeadBob)
    {
    return;
    }
    if (m_CharacterController.velocity.magnitude > 0 && m_CharacterController.isGrounded)
    {
    m_Camera.transform.localPosition =
    m_HeadBob.DoHeadBob(m_CharacterController.velocity.magnitude +
    (speed*(m_IsWalking ? 1f : m_RunstepLenghten)));
    newCameraPosition = m_Camera.transform.localPosition;
    newCameraPosition.y = m_Camera.transform.localPosition.y - m_JumpBob.Offset();
    }
    else
    {
    newCameraPosition = m_Camera.transform.localPosition;
    newCameraPosition.y = m_OriginalCameraPosition.y - m_JumpBob.Offset();
    }
    m_Camera.transform.localPosition = newCameraPosition;
    }


    private void GetInput(out float speed)
    {
    // Read input
    float horizontal = CrossPlatformInputManager.GetAxis("Horizontal");
    float vertical = CrossPlatformInputManager.GetAxis("Vertical");

    bool waswalking = m_IsWalking;

    #if !MOBILE_INPUT
    // On standalone builds, walk/run speed is modified by a key press.
    // keep track of whether or not the character is walking or running
    m_IsWalking = !Input.GetKey(KeyCode.LeftShift);
    #endif
    // set the desired speed to be walking or running
    speed = m_IsWalking ? m_WalkSpeed : m_RunSpeed;
    m_Input = new Vector2(horizontal, vertical);

    // normalize input if it exceeds 1 in combined length:
    if (m_Input.sqrMagnitude > 1)
    {
    m_Input.Normalize();
    }

    // handle speed change to give an fov kick
    // only if the player is going to a run, is running and the fovkick is to be used
    if (m_IsWalking != waswalking && m_UseFovKick && m_CharacterController.velocity.sqrMagnitude > 0)
    {
    StopAllCoroutines();
    StartCoroutine(!m_IsWalking ? m_FovKick.FOVKickUp() : m_FovKick.FOVKickDown());
    }
    }


    private void RotateView()
    {
    m_MouseLook.LookRotation (transform, m_Camera.transform);
    }


    private void OnControllerColliderHit(ControllerColliderHit hit)
    {
    Rigidbody body = hit.collider.attachedRigidbody;
    //dont move the rigidbody if the character is on top of it
    if (m_CollisionFlags == CollisionFlags.Below)
    {
    return;
    }

    if (body == null || body.isKinematic)
    {
    return;
    }
    body.AddForceAtPosition(m_CharacterController.velocity*0.1f, hit.point, ForceMode.Impulse);
    }
    }
    }
     
  11. Si2G

    Si2G

    Joined:
    Feb 22, 2020
    Posts:
    6
    I've got the same problem here. That line 6 that people are talking about is not the same.
    Is there another, more reliable, first person controller available on the asset store?
     
  12. charlesb_rm

    charlesb_rm

    Joined:
    Jan 18, 2017
    Posts:
    485
    santillanjorge likes this.
  13. unity_2D23811446D4A3030893

    unity_2D23811446D4A3030893

    Joined:
    Sep 19, 2022
    Posts:
    1
    it worked!!!!
     
  14. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,689
    The complete error message contains everything you need to know to fix the error yourself.

    The important parts of the error message are:

    - the description of the error itself (google this; you are NEVER the first one!)
    - the file it occurred in (critical!)
    - the line number and character position (the two numbers in parentheses)
    - also possibly useful is the stack trace (all the lines of text in the lower console window)

    Always start with the FIRST error in the console window, as sometimes that error causes or compounds some or all of the subsequent errors. Often the error will be immediately prior to the indicated line, so make sure to check there as well.

    All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don't have to stop your progress and fiddle around with the forum.

    Remember: NOBODY here memorizes error codes. That's not a thing. The error code is absolutely the least useful part of the error. It serves no purpose at all. Forget the error code. Put it out of your mind.

    If you just need a character controller, here's a great one:

    https://forum.unity.com/threads/a-basic-first-person-character-controller-for-prototyping.1169491/