Search Unity

Tank tutorial issue: No MonoBehaviour scripts in the file...

Discussion in 'Editor & General Support' started by brandnamewater, Nov 15, 2019.

  1. brandnamewater

    brandnamewater

    Joined:
    Nov 15, 2019
    Posts:
    4
    I'm doing the Tank tutorial:


    I am at the point (time stamped in URL) where you take the C# assets code and drag it into the tank but I keep receiving the error "can't add scrript behaviour AuthorityOnSpawnedObjectsIsCorrect. The script needs to derive from MonoBehaviour.

    I keep reading the file name and public class need to match, which they do. This is also the default files from the tutorial provided. I see others having this issue but I have not had a case where it is solved yet.

    Here is the file:

    (File name is "TankMovement")

    I also tried changing it to "TankMovement.cs"

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class TankMovement : MonoBehaviour
    4. {
    5.     public int m_PlayerNumber = 1;        
    6.     public float m_Speed = 12f;          
    7.     public float m_TurnSpeed = 180f;      
    8.     public AudioSource m_MovementAudio;  
    9.     public AudioClip m_EngineIdling;      
    10.     public AudioClip m_EngineDriving;    
    11.     public float m_PitchRange = 0.2f;
    12.  
    13.     /*
    14.     private string m_MovementAxisName;    
    15.     private string m_TurnAxisName;        
    16.     private Rigidbody m_Rigidbody;        
    17.     private float m_MovementInputValue;  
    18.     private float m_TurnInputValue;      
    19.     private float m_OriginalPitch;        
    20.  
    21.  
    22.     private void Awake()
    23.     {
    24.         m_Rigidbody = GetComponent<Rigidbody>();
    25.     }
    26.  
    27.  
    28.     private void OnEnable ()
    29.     {
    30.         m_Rigidbody.isKinematic = false;
    31.         m_MovementInputValue = 0f;
    32.         m_TurnInputValue = 0f;
    33.     }
    34.  
    35.  
    36.     private void OnDisable ()
    37.     {
    38.         m_Rigidbody.isKinematic = true;
    39.     }
    40.  
    41.  
    42.     private void Start()
    43.     {
    44.         m_MovementAxisName = "Vertical" + m_PlayerNumber;
    45.         m_TurnAxisName = "Horizontal" + m_PlayerNumber;
    46.  
    47.         m_OriginalPitch = m_MovementAudio.pitch;
    48.     }
    49.     */
    50.  
    51.     private void Update()
    52.     {
    53.         // Store the player's input and make sure the audio for the engine is playing.
    54.     }
    55.  
    56.  
    57.     private void EngineAudio()
    58.     {
    59.         // Play the correct audio clip based on whether or not the tank is moving and what audio is currently playing.
    60.     }
    61.  
    62.  
    63.     private void FixedUpdate()
    64.     {
    65.         // Move and turn the tank.
    66.     }
    67.  
    68.  
    69.     private void Move()
    70.     {
    71.         // Adjust the position of the tank based on the player's input.
    72.     }
    73.  
    74.  
    75.     private void Turn()
    76.     {
    77.         // Adjust the rotation of the tank based on the player's input.
    78.     }
    79. }
    How can I have this working? I really want to finish this
     
  2. MSplitz-PsychoK

    MSplitz-PsychoK

    Joined:
    May 16, 2015
    Posts:
    1,278
    Do you have any red compiler errors in your console? This will prevent new scripts from doing anything, including detecting monobehaviours.

    If that's not it, try creating a new script called TankMovement, copy & paste the code from your script that wasn't working, then delete the script that wasn't working.

    If that still doesn't do it, try the previous step again, but with a different filename for the script, and change the class name to match it.

    Good luck!