Unity- vs code error: if ($?) { dotnet run $Player_Movement } (Solved) - c#

Hi I am getting "cd "c:\Users\UMUT\Desktop\Unity Projects\Newest\Assets" ; if
($?) { dotnet run $Player_Movement }" message and I get this error message "Couldn't find a project to run. Ensure a project exists in C:\Users\UMUT\Desktop\Unity Projects\Newest\Assets, or pass the path to the project using --project." in my Vs code Unity project. İn my another old project I have a C# script named Player_Movement but I am getting this error in my new Unity Project when I try to debug the project.I downloaded C# extension.I downl Any solutions or reason why it is happening?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class New : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
Debug.Log("hi");
}
// Update is called once per frame
void Update()
{
}
}
I resetted Vs code settings and change my C# extension to older version and error fixed.

I reseted Vs code settings to default and my problem is fixed.

Related

My visual studio script is not working in Unity

I just started game development and got into a problem
whenever I load my Visual Studio code into Unity it says
The refrenced script unknown on this behaviour is missing
This is my script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class VirtualManMovement : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
Debug.Log("Hello, World!") ;
}
// Update is called once per frame
void Update()
{
}
}
I need a solution for this
This may happen is the file name does not match the class name. Make sure that the file containing this script is also named VirtualManMovement.cs
Make sure in Unity you go to edit -> preferences and see that you have Unity External tools in Your IDE Selected.
Ensure your Code File Name is the same as your Class to prevent confusion.
I was confused as well when I first started. Hopefully, you find this useful

Unity: IPreprocessBuildWithReport is not running on Build

I am a new with Unity and I have been trying to build a Unity project where when it is built, it can also copy some files with the game.exe in the Build folder. For that, I need to understand how IPreprocessBuildWithReport works.
I have created a C# script called MyCustomBuildProcessor.cs and put it inside: Assets\Scripts\Editor The script is as follows:
//Implement this function to receive a callback before the build is started.
using UnityEditor;
using UnityEditor.Build;
using UnityEditor.Build.Reporting;
using UnityEngine;
class MyCustomBuildProcessor : IPreprocessBuildWithReport
{
public int callbackOrder { get { return 0; } }
public void OnPreprocessBuild(BuildReport report)
{
Debug.Log("MyCustomBuildProcessor.OnPreprocessBuild for target " + report.summary.platform + " at path " + report.summary.outputPath);
}
}
To my understanding, this script should run when I build the project, but the Log is not shown in the console. Can someone explain to me what I am doing wrong?
My build setting is as follows:
Unity Build Settings Image , Unity Project Files
My Unity version is: 2022.1.20f1
I have tried building in different version like 2021.3.10f1 and tried placing the file in outside the Editor folder but nothing has worked. Maybe there is something basic that I am missing. I am new to the Unity scene so I have no idea what I am doing wrong.

Visual Studio Intellisense for UnityEngine not working

I am trying to write a script for Unity in C#. I created the script and then I opened it. When I typed in Ge, I don't get Unity methods (I only see GetHashCode and GetType). I am looking for GetComponent. I tried writing the script (from a tutorial) and it works fine in Unity, so only the intellisense is not working. It also doesn't work for new Vector3().
I am using Visual Studio Community 2019 (v 16.5.2).
The complete script is:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AddConstantVelocity : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
GetComponent<Rigidbody>().velocity = new Vector3(2, 10, -6);
}
}
You need to specify VS Code as the default editor.
Edit > Prefernces > External tools > External Script Editor

How to use unsafe context in Unity

I want to use c++ code in c# for Unity using CLR.
The program works properly outside of unity, but inside of engine it gives me an error:
"cs0227: unsafe code requires the 'unsafe' command line option to be specified"
I am really confused, because the project builds successfully in visual studio (without any errors or warnings). I have "allow unsafe" button activated.
using UnityEngine;
using System.Collections;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public class newspawn_real : MonoBehaviour {
void Start () {
unsafe
{
fixed (int * p = &bam[0, 0, 0])
{
CppWrapper.CppWrapperClass controlCpp = new CppWrapper.CppWrapperClass();
controlCpp.allocate_both();
controlCpp.fill_both();
controlCpp.fill_wrapper();
}
}
}
// ...
}
You have to explicitly enable unsafe code in Unity. You can follow the steps below:
1. First step, Change Api Compatibility Level to .NET 2.0 Subset.
2. Create a file in your <Project Path>/Assets directory and name it smcs.rsp then put -unsafe inside that file. Save and close that file.
Close and reopen Visual Studio and Unity Editor.
You must restart both of them.
It's worth noting that even after doing this and restarting both Unity and Visual Studio, if the problem is still there,
Rename the smcs.rsp file to csc.rsp, gmcs.rsp or mcs.rsp
Restart Unity Editor and Visual Studio each time until you get one that works. For more details about the file name to use, refer to Platform Dependent Compilation documentation.
Simple C# unsafe code that compiles after this.
public class newspawn_real : MonoBehaviour
{
unsafe static void SquarePtrParam(int* p)
{
*p *= *p;
}
void Start()
{
unsafe
{
int i = 5;
// Unsafe method: uses address-of operator (&):
SquarePtrParam(&i);
Debug.Log(i);
}
}
}
update:
on unity 2019 and forward, we don't have the 2.0 subset.
use 2.0 Standard.
and although mcs.rsp works, there is a warning noting that mcs is obsolete, and we should use csc.rsp instead.
but it actually works !

SpeechLib.SpVoiceClass:GetVoices does crash my Unity executable

I created a project with Unity (version 4.5.3f3).
I only wrote a simple script as follow:
using UnityEngine;
using System.Collections;
using SpeechLib;
public class SpeechTest : MonoBehaviour
{
private SpVoice voice;
void Start()
{
voice = new SpVoice();
voice.GetVoices("","");
}
// Update is called once per frame
void Update()
{
if (Input.anyKeyDown)
{
voice.Speak("Hello, world!", SpeechVoiceSpeakFlags.SVSFlagsAsync);
}
}
}
Here you can download the test project for Unity: https://dl.dropboxusercontent.com/u/12184013/TextToSpeech.zip
When I try to play (in Unity editor), the game runs without problems.
Instead, when I build and run the game, it crashes.
When i comment this line
ISpeechObjectTokens voices = voice.GetVoices();
the game doesn't crash after I rebuilt it.
I need to call GetVoices method, because I want to set a new voice in the "SpVoice voice" object.
Here is the solution: http://forum.unity3d.com/threads/speechlib-spvoiceclass-getvoices-does-crash-my-unity-executable.268011/#post-1772720
In a nutshell the library [Unity Install Directory]\Editor\Data\Mono\lib\mono\2.0\CustomMarshalers.dll should be included in the Unity project (adding it as a asset).

Categories