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.
Related
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
I'm currently trying to connect the Arduino Nano 33 IoT board to Unity.
This code simply makes the GameObject vanish if Unity reads something from the board.
While coding, there are some SerialPort problems, and I've tried a few solutions like adjusting the API compatibility Level in Unity or something else, but it ain't worked for me as well...
The following is my code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO.Ports;
using System;
public class Nano33IoT : MonoBehaviour
{
public GameObject nano33IoT;
SerialPort sp = new SerialPort("usbmodem11101", 9600);
float m;
void Start()
{
sp.Open();
sp.ReadTimeout = 1;
}
void FixedUpdate()
{
if (sp.IsOpen)
{
try
{
string value = sp.ReadLine();
if (value != "")
{
Debug.Log("Value: " + value);
nano33IoT.SetActive(false);
}
}
catch (TimeoutException)
{
throw;
}
}
}
void Update()
{
}
}
Things just don't work as expected, there are 2 problems that I encountered:
If I switch the API compatibility Level to .NET framework in Unity (Edit > Project Settings > player > API compatibility Level), then the VS code will report an error, saying:
The type or namespace name 'Ports' does not exist in the namespace 'System.IO' (are you missing an assembly reference?) [Assembly-CSharp]. The weird thing is, Unity reports nothing. So I decide to ignore the error and press the play button anyway.
But in runtime, Unity reports an error:
IOException: No such file or directory
System.IO.Ports.SerialPort.Open() (at sp.Open() in Start function)
If I switch the API compatibility Level to .NET 2.1, then the Unity compilation will report the same error as above, but the VS code works just fine and causes the Unity project unrunnable… so confusing🤯
Please help me with this so I can make the world better
Much Appreciated🥹
I'm currently working on a game and I was making it's options menu and started scripting the fullscreen toggle. The code I've used for this can be found in a Brackeys tutorial but even after following whatever they did I've ran into this error:
Assets\Code\OptionsMenuScript.cs(44,16): error CS0117: 'Screen' does not contain a definition for 'fullscreen'
Most of the code in OptionsMenuScript.cs is useless in this question so I'll narrow it down to the important parts.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class SwitchToFullscreen : MonoBehaviour
{
public void SetFullscreen(bool isFullscreen)
{
Screen.fullscreen = isFullscreen;
}
}
Even after looking in Project Settings several times I still haven't found a way to fix this. Am i supposed to define screen somewhere in my code? Is screen in the Project Settings but under a different name? Can anybody help me with this?
Also, if anyone needs it, I'm using Unity 2021.3.3f1 (3D Project).
public void SetFullscreen(bool isFullscreen) {
Screen.fullScreen = isFullscreen;
}
your Screen.fullScreen doesn't match with capitalization which I believe is throwing the errors. I tested using the code written above and received no errors in visual studio.
I am using rage multiplayer server that runs on C# scripts. It makes it possible for gta v to play on a server with custom game modes.
The problem is this:
The type or namespace name 'Player' could not be found (are you missing a using directive or an assembly reference?)
I followed this tutorial https://www.youtube.com/watch?v=HLRFF6A36mM
the code is here:
using System;
using System.Collections.Generic;
using System.Text;
using GTANetworkAPI;
namespace gtavrp.Commands
{
class PlayerCommands : Script
{
//~o~ stands for orange ~w~ stands for white
//Below that is the description
[Command("me", "~o~Usage: ~w~ /me [action]", GreedyArg = true)]
public void CMD_Me(Player player, string action)
{
//This removes the extra spaces inside the chat
action = action.Trim();
List<Player> nearbyPlayers = NAPI.Player.GetPlayersInRadiusOfPlayer(20, player);
foreach (Player item in nearbyPlayers)
{
item.SendChatMessage($"~p~{player.Name} {action}");
}
}
}
}
I've tried adding this line of code:
using GTANetworkMethods;
but it still didn't repair the problem, because I have ended up having a problem with the item.SendChatMessage, even though it did stop marking the Player as an error
I did replace the Player with Client, and still no success, the script does not load when the server runs if it is replaced with the Client instead of Player.
Please do help, I don't know how to fix this problem
I am using Unity to develop a game and I want to use Kinect so I add a reference to Microsoft.Kinect.ddl and I have the following code (nothing impressive):
using UnityEngine;
using System.Collections;
using Microsoft.Kinect;
public class Main : MonoBehaviour {
// Use this for initialization
void Start () {
print(KinectSensor.KinectSensors.Count);
}
// Update is called once per frame
void Update () {
}
}
Visual Studio does not mark any error but when I am trying to run it using Unity I am getting a compilation error The type or namespace name Kinect does not exist in the namespace Microsoft . Any idea how can I fix that?
See this page for using the SDK with unity. It does have some obvious errors though (as pointed out in the documentation.)
I am using k2examples asset from the asset store, and I ran into the same problem... since you are not using the same asset, this might not solve the problem, but you can give it a try:
import the standard assets.