GUIText replacement? - c#

Alright so I'm learning unity right now and I opened my game this morning and ran into this error code
Assets\Standard Assets\Utility\SimpleActivatorMenu.cs(11,16): error CS0619:
'GUIText' is obsolete: 'GUIText has been removed. Use UI.Text instead.'
I have tried replacing GUIText with UI.Text however that lead to a different error messages of:
Assets\Standard Assets\Utility\SimpleActivatorMenu.cs(11,16): error CS0246:
The type or namespace name 'UI' could not be found (are you missing a using
directive or an assembly reference?)
or
Assets\Standard Assets\Utility\SimpleActivatorMenu.cs(11,16): error CS0246:
The type or namespace name 'UIText' could not be found (are you missing a using
directive or an assembly reference?)
Can anybody help me out here?

You cannot simply replace GUIText with Text unfortunately. Check this answer out:
GUIText is deprecated, so what should I use instead of it?

you can just replace it using Text from UnityEngine.UI
Here's an example:
using UnityEngine.UI;
namespace YourNameSpace.Utility
{
public class YourClass : MonoBehaviour
{
public Text myText;
void Start()
{
myText.text = "Your text here";
}
}
}

You should fallow these steps
adding "using UnityEngine.UI;" begining of .cs file
change all GUIText to Text.

Add this line :
using UnityEngine.UI;
and then replace :
GUIText with Text

Related

How to fix: The type or namespace name 'MouseLook' could not be found

Help. I was making code for the game on Unity, but something went wrong and I got 2 errors:
error CS0246: The type or namespace name 'MouseLook' could not be found (are you missing a using directive or an assembly reference?)
error CS0246: The type or namespace name 'PlayerMovement' could not be found (are you missing a using directive or an assembly reference?)
Please help!
I tried to create a game on Unity, and using the photon network I created multiplayer. But I got these 2 errors, I do not understand how to solve them. Please help me I will be very grateful
code:
using UnityEngine;
using Photon.Pun;
public class IsMine : MonoBehaviour
{
[SerializeField] private PlayerMovement _playerMovement;
[SerializeField] private MouseLook _mouseLook;
[SerializeField] private GameObject _camera;
[SerializeField] private PhotonView _photonView;
[SerializeField] private GameObject _playerModel;
void Start()
{
if (!_photonView.IsMine)
{
_playerMovement.enabled = false;
_mouseLook.enabled = false;
_camera.SetActive(false);
_playerModel.SetActive(true);
}
}
}
In this context 'PlayerMovement' and 'MouseLook' are both classes. Somewhere in your unity solution you need to have both of these classes that the game can make a valid reference to.

The type or namespace ,,blabla" error appearing after i build

As the title suggests, when i'm trying to build my unity project on my phone i get:
error CS0246: The type or namespace name 'InitializeOnLoadMethod' could not be found (are you missing a using directive or an assembly reference?)
But the project is working fine. No errors in visual studio, no errors while playing the game, nothing.
I tried to change the solution .NET version in visual studio from
.NET Framework 4.7.1
to
unity 3.5 .net full Base Class Libraries
(i did that without really knowing what i was doing so maybe i did something wrong)
But then i got even more errors. Can someone please explain what to do? i fell helpless
using System.Linq;
using System.Reflection;
using UnityEditor;
using UnityEngine;
[ExecuteInEditMode]
public class ExecuteOnRefresh : MonoBehaviour
{
[InitializeOnLoadMethod]
private static void OnInitialized()
{
var propTypes = Assembly.GetAssembly(typeof(Property)).GetTypes().Where(myType => myType.IsClass && !myType.IsAbstract && myType.IsSubclassOf(typeof(Property)));
EntityBuild.PROP_NAMES = propTypes.Select(type => type.ToString()).ToList();
}
}
InitializeOnLoadMethod attribute is editor-only stuff. Either you have to move your script in a folder named "Editor", or surround your code between #if UNITY_EDITOR - #endif, so Unity won't try to compile it into the build.
https://docs.unity3d.com/ScriptReference/InitializeOnLoadMethodAttribute.html

The type or namespace couldn't be find , how to fix it?

So im doing a unity car game and one of my script for the physics is not working and i dont know why.
there is my code :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(InputManager))]
public class CarController : MonoBehaviour
{
public InputManager im;
public List<wheelCollider> steeringWheel;
public List<wheelCollider> piloteWheel;
and i got the following errors : "error CS0246: The type or namespace name 'wheelCollider' could not be found (are you missing a using directive or an assembly reference?)"
Do you know how to fix it ?
You have a typo, 'wheelCollider' should be 'WheelCollider' with an uppercase 'W'.

Unity build setting error

I'm using Unity 5.6.0f3 and have come across this error when I try build and run.
Ive checked in monodeveloper building and running script and it says build success. when I try for windows/mac/Linux standlone I get the below error messages.
Assets/Scripts/LevelManager.cs(4,19): error CS0234: The type or
namespace name SceneManagement' does not exist in the
namespaceUnityEngine'. Are you missing an assembly reference?
Assets/Scripts/LevelManager.cs(6,29): error CS0246: The type or
namespace name `MonoBehaviour' could not be found. Are you missing an
assembly reference?
Error building Player because scripts had compiler errors
.cs is as follows
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class LevelManager : MonoBehaviour {
public void Loadevel(string name) {
Debug.Log("Level load requested for: " + name);
SceneManager.LoadScene(name);
Debug.Log("Loaded Level " + name);
}
public void QuitLevel(string name) {
Debug.Log("I want to Quit");
Application.Quit();
}
}
Im cant seem to find any answer on the net and am unable to figure it out at present.
I had similar problem.
Reimporting assests didn't help, as restarting the computer, reinstaling the same version of unity and reinstalling visual studio.
Finnaly I got it to work by updating to unity beta.

missing a using directive or an assembly reference?

I am getting this error Error 4 The type or namespace name 'Sample' could not be found (are you missing a using directive or an assembly reference?) F:\oadmin\sea\Controls\Dlg.cs 11 7 Controls
here i added Samplein reference section,,,then i used it as Using Sample,,i dont know why i am getting this error
this is the class
namespace sample
{
public class Server
{
public class client
{
Bool sent = true
}
}
}
Can i share exe,,this Sample is an exe
Perhaps because your namespace is sample and not Sample?
So if your Dlg namespace is different it needs to have a using sample line not using Sample.
Or perhaps your class is in another project within your solution and you need to include the hierarchy of namespaces?
Your namespace "sample" is lowercase, but you are referring to it in uppercase "Sample" ...
EDIT: You Bool sent is internal, it cannot be accessed from outside of the assembly

Categories

Resources