For reasons, I need to use PowerShell to get information about the computer's IP. Therefore, I tried using System.Management.Automation along with NugetForUnity, but VS keeps saying that The type or namespace name 'Automation' does not exist in the namespace 'System.Management' (are you missing an assembly reference?) I know for a fact that I have installed the package, but I have not gotten anywhere with this project for the past 4 hours. Does anybody have any advice? Here is my code:
using System.Management.Automation;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class getLocation : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
//https://www.codeproject.com/Questions/1206308/Powershell-commands-from-Csharp
//Modified by #alex#6555
using (var ps = PowerShell.Create())
{
ps.AddCommand("curl");
ps.AddArgument("ipinfo.io");
}
}
// Update is called once per frame
void Update()
{
}
}
If anybody knows what to do, some pointers would be greatly appreciated.
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 try to use the following class in Unity
https://learn.microsoft.com/de-de/dotnet/api/system.security.cryptography.ecdiffiehellmancng?view=net-6.0
So my Code is simply:
using System;
using System.Collections;
using System.Text;
using UnityEngine;
using System.Security.Cryptography;
using System.IO;
public class SomeClass : MonoBehaviour
{
IEnumerator Start()
{
using (ECDiffieHellmanCng alice = new ECDiffieHellmanCng())
{ }
}
Unity responds like :
Assets\Scripts\TcpClientAsyncBehaviour.cs(27,16): error CS0246: The type or namespace name 'ECDiffieHellmanCng' could not be found (are you missing a using directive or an assembly reference?)
So i got the nugget File from here
https://www.nuget.org/packages/System.Security.Cryptography.Cng/6.0.0-preview.4.21253.7
made it a zip file and extracted the System.Security.Cryptography.Cng.dll from lib/netstandard2.0 and put it into unity.
Nothing changed.
I also tried the UnityNuget package but it refuses to install the nugget I would need.
I also tried to use an rsp File with the content -r:System.Security.dll and copied it into Unity still nothing.
Please help!
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.