Search Unity

A Fix To CS0246?

Discussion in 'Scripting' started by emoney101skeleton, Jun 23, 2020.

  1. emoney101skeleton

    emoney101skeleton

    Joined:
    Jun 7, 2020
    Posts:
    12
    So I Had To Fix This Script I Think I did What They Ask I Still Get This Errror

    error CS0246: The type or namespace name 'UI' could not be found (are you missing a using directive or an assembly reference?)

    using System;
    using UnityEngine;

    #pragma warning disable 618
    namespace UnityStandardAssets.Utility
    {
    public class SimpleActivatorMenu : MonoBehaviour
    {
    // An incredibly simple menu which, when given references
    // to gameobjects in the scene
    public UI camSwitchButton;
    public GameObject[] objects;


    private int m_CurrentActiveObject;


    private void OnEnable()
    {
    // active object starts from first in array
    m_CurrentActiveObject = 0;
    camSwitchButton.text = objects[m_CurrentActiveObject].name;
    }


    public void NextCamera()
    {
    int nextactiveobject = m_CurrentActiveObject + 1 >= objects.Length ? 0 : m_CurrentActiveObject + 1;

    for (int i = 0; i < objects.Length; i++)
    {
    objects.SetActive(i == nextactiveobject);
    }

    m_CurrentActiveObject = nextactiveobject;
    camSwitchButton.text = objects[m_CurrentActiveObject].name;
    }
    }
    }[/code]


    Yet Don't Know I Might Have Re Learned Coding But This Puzzled Me
     
  2. Kudos for using half the CODE tag. Please use both of them :)
    https://forum.unity.com/threads/using-code-tags-properly.143875/

    I will presume that you want to refer to a Button. So this
    should be something like this:
    Code (CSharp):
    1. using UnityEngine.UI;
    2. [...]
    3. public Button camSwitchButton;