Click here to Skip to main content
16,004,761 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
THIS ERROR IS COMING .

Assets\Standard Assets\Utility\SimpleActivatorMenu.cs(38,31): error CS0029: Cannot implicitly convert type 'string' to 'UnityEngine.UI.Text'

What I have tried:

THIS IS MY SCRIPT .

C#
using UnityEngine;
using System.Collections;
using UnityEngine.UI;



#pragma warning disable 618
namespace UnityStandardAssets.utility
{
    public class SimpleActivatorMenu 
    {
        
        public Text camSwitchButton ;
        public GameObject[] objects;


        private int m_CurrentActiveObject;


        private void OnEnable(){
        
            // active object starts from first in array
            m_CurrentActiveObject = 0;
            camSwitchButton = 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[i].SetActive(i == nextactiveobject);
            }

            m_CurrentActiveObject = nextactiveobject;
            camSwitchButton = objects[m_CurrentActiveObject].name;
             
             
        }
    }
}
Posted
Updated 6-Aug-21 5:35am
v2
Comments
PIEBALDconsult 6-Aug-21 10:40am    
Is this a third re-post of the same question?
Member 15309599 6-Aug-21 10:48am    
NO
Richard MacCutchan 6-Aug-21 11:35am    
Well it is almost the same. See my solution below.

Quote:
C#
camSwitchButton = objects[m_CurrentActiveObject].name;
You are trying to store a string value in a variable which can only hold instances of the Text class. The compiler is (correctly) telling you that you can't do that.

As we keep telling you, STOP guessing, and start reading the documentation or following a decent tutorial. Posting a new question here every time you try to shove the square peg in the round hole and fail is NOT a sensible way to learn how to write code.
 
Share this answer
 
Maybe if you actually consulted the documentation ... Unity - Scripting API: UI.Text.text[^]. Which clearly shows how to assign a string to a Text object.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900