Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

Question I need help with fixing CS0246

Discussion in 'Scripting' started by atten0007, Dec 27, 2021.

  1. atten0007

    atten0007

    Joined:
    Jun 25, 2021
    Posts:
    45
    Hi folks,

    I'm currently coding on my both games Mikacraft and Mikacity. When they're finished, I want to publish them on multiple App stores (e.g. Apple App Store, Google Play Store etc.), but in my game is currently four times the very ****** compiler error CS0246: The type or namespace name 'UI' couldn't be found, but I added using Unity.UI to the script top. These are the compiler errors:

    Assets/Infiniterrain/Standard Assets/Utility/ForcedReset.cs(9,27): error CS0246: The type or namespace name 'UI' could not be found (are you missing a using directive or an assembly reference?)

    Assets/Infiniterrain/Standard Assets/Utility/FPSCounter.cs(10,31): error CS0246: The type or namespace name 'UI' could not be found (are you missing a using directive or an assembly reference?)

    Assets/Infiniterrain/Standard Assets/Utility/FPSCounter.cs(17,17): error CS0246: The type or namespace name 'UI' could not be found (are you missing a using directive or an assembly reference?)

    Assets/Infiniterrain/Standard Assets/Utility/SimpleActivatorMenu.cs(13,16): error CS0246: The type or namespace name 'UI' could not be found (are you missing a using directive or an assembly reference?)

    And here're the scripts with the very ****** compiler errors:

    The script FPSCounter.cs:
    Code (CSharp):
    1.  
    2. using System;
    3. using System.Collections;
    4. using System.Collections.Generic;
    5. using System.Diagnostics;
    6. using UnityEngine;
    7. using UnityEngine.UI;
    8. using UnityStandardAssets.Utility;
    9.  
    10. namespace UnityStandardAssets.Utility {
    11.     [RequireComponent(typeof (UI.Text))]
    12.     public class FPSCounter : MonoBehaviour {
    13.         const float fpsMeasurePeriod = 0.5f;
    14.         private int m_FpsAccumulator = 0;
    15.         private float m_FpsNextPeriod = 0;
    16.         private int m_CurrentFps;
    17.         const string display = "{0} FPS";
    18.         private UI.Text m_GuiText;
    19.  
    20.  
    21.         private void Start() {
    22.             m_FpsNextPeriod = Time.realtimeSinceStartup + fpsMeasurePeriod;
    23.             m_GuiText = GetComponent<UI.Text>();
    24.         }
    25.  
    26.  
    27.         private void Update() {
    28.             // measure average frames per second
    29.             m_FpsAccumulator++;
    30.             if (Time.realtimeSinceStartup > m_FpsNextPeriod) {
    31.                 m_CurrentFps = (int) (m_FpsAccumulator/fpsMeasurePeriod);
    32.                 m_FpsAccumulator = 0;
    33.                 m_FpsNextPeriod += fpsMeasurePeriod;
    34.                 m_GuiText.text = string.Format(display, m_CurrentFps);
    35.             }
    36.         }
    37.     }
    38. }
    39.  
    The script SimpleActivatorMenu.cs:

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

    Code (CSharp):
    1.  
    2. using UnityStandardAssets.CrossPlatformInput;
    3. using System;
    4. using System.Collections;
    5. using System.Collections.Generic;
    6. using System.Diagnostics;
    7. using UnityEngine;
    8. using UnityEngine.UI;
    9.  
    10. [RequireComponent(typeof (UI.Texture))]
    11. public class ForcedReset : MonoBehaviour {
    12.     private void Update() {
    13.         // if we have forced a reset ...
    14.         if (CrossPlatformInputManager.GetButtonDown("ResetObject")) {
    15.             //... reload the scene
    16.             Application.LoadLevelAsync(Application.loadedLevelName);
    17.         }
    18.     }
    19. }
    20.  
    If you can tell me, how I can fix these very ****** compiler errors, I'll be very happy because I want to maybe publish my game tomorrow to steam.

    Sincerely yours,
    Atten007
     
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,190
    As it says. UI isn't recognized. Because UI.Text isn't correct. Since you have a using statement up top, just set it to Text. Otherwise, it would have to be UnityEngine.UI.Text if you weren't using the using statement.
     
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,835
    BABIA_GameStudio and Brathnann like this.