Search Unity

error CS1585: Member modifier 'private' must precede the member type and name"

Discussion in 'Scripting' started by Gentleman17, Jul 29, 2020.

  1. Gentleman17

    Gentleman17

    Joined:
    Jul 29, 2020
    Posts:
    1
    hello,
    in the line18 of the code (private void OnEnable()) we have error "error CS1585: Member modifier 'private' must precede the member type and name", and Idon't know what doing. Help me , guys!

    Code (CSharp):
    1. using System;
    2. using UnityEngine;
    3.  
    4. #pragma warning disable 618
    5. namespace UnityStandardAssets.Utility
    6. {
    7.     public class SimpleActivatorMenu : MonoBehaviour
    8.     {
    9.         // An incredibly simple menu which, when given references
    10.         // to gameobjects in the scene
    11.         public UI.Text camSwitchButton;
    12.         public GameObject[] objects;
    13.  
    14.  
    15.         private int m_CurrentActiveObject;
    16.         UI.Text
    17.  
    18.         private void OnEnable()
    19.         {
    20.             // active object starts from first in array
    21.             m_CurrentActiveObject = 0;
    22.             camSwitchButton.text = objects[m_CurrentActiveObject].name;
    23.         }
    24.  
    25.  
    26.         public void NextCamera()
    27.         {
    28.             int nextactiveobject = m_CurrentActiveObject + 1 >= objects.Length ? 0 : m_CurrentActiveObject + 1;
    29.  
    30.             for (int i = 0; i < objects.Length; i++)
    31.             {
    32.                 objects[i].SetActive(i == nextactiveobject);
    33.             }
    34.  
    35.             m_CurrentActiveObject = nextactiveobject;
    36.             camSwitchButton.text = objects[m_CurrentActiveObject].name;
    37.         }
    38.     }
    39. }
    40.  
     
  2. ??? Line 16.
     
  3. Owen-Reynolds

    Owen-Reynolds

    Joined:
    Feb 15, 2012
    Posts:
    1,998
    Yeah, a thing to know about errors is they're often noticed a line or two after the real problem. If you get an error on line 107, especially when it's the first thing, check the line above. The most common way is forgetting the semicolon at the end of a line -- the error is always the first thing on the next line.

    In this case it saw UI.Text on line 16, with no semicolon. It's not an error, yet. It goes to line 18 and sees, altogether "UI.Text private". Well that's an error for sure -- private has to come first. So now it gives the error, on the "wrong" line.
     
  4. TheOtherUserName

    TheOtherUserName

    Joined:
    May 30, 2020
    Posts:
    136
    I don't know if the name of an object can be displayed as an UI text so I would also try to write .ToString() at the end because Unity only debugs to the first major error like an incorrect function not as with ints or strings that are missing