I have tried both without OnGUI and with OnGUI and I can not really understand the errors they are giving.
I do not really understand what an error like
Internal build system error. BuildProgram exited with code -2146233088.
error: Build path contains project built with "Create Visual Studio Solution" option, which is incompatible with current build settings. Consider building your project into an empty directory.
System.Exception: Build path contains project built with "Create Visual Studio Solution" option, which is incompatible with current build settings. Consider building your project into an empty directory.
at WinPlayerBuildProgram.WinPlayerPrerequisiteChecks.CheckSafeProjectOverwrite(PlayerBuildConfig playerBuildConfig)
at WinPlayerBuildProgram.WinPlayerBuildProgram..ctor(String[] args)
at PlayerBuildProgramTypeWrapper.Run(String[] args)
at Program.Main(String[] args)
UnityEditor.BuildPlayerWindow:BuildPlayerAndRun ()
means and I do not know the problem with this code
using System.Collections;
using System.Collections.Generic;
using System;
using UnityEngine;
public class SquareScript : MonoBehaviour
{
void Start()
{
transform.position = new Vector3(1, 0);
}
void Update()
{
transform.position = new Vector3((float)Math.Cos(Time.time), (float)Math.Sin(Time.time));
}
void OnGUI()
{
GUI.Label(new Rect(-0.5f, 0.5f, -0.5f, 0.5f), "lol");
}
}
And by the way it has nothing to do with the stuff in void Start() or void Update() since I tested that without the GUI stuff and it works fine.
Related
I am trying to use my C++ dll on Unity, so I copied it in Assets/Plugins and at the root of the project but I have DllFoundException when I use the Play button or run the .exe file generated by the build. It doesn't even work when I use the absolute path of the dll file in the DllImport.
However, it works fine when I Build&Run the project.
Unity Code
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using UnityEngine;
using Dummiesman;
public class morph_face : MonoBehaviour
{
bool morphed;
[DllImport(#"facemorph", CallingConvention=CallingConvention.Cdecl)]
static extern void morphModelsPoints(string src_model, string src_csv,
string dst_csv, string output_path);
public GameObject model;
// Start is called before the first frame update
void Start()
{
morphed = false;
}
// Update is called once per frame
void Update()
{
if (!morphed && Input.GetKeyDown("space")) {
Debug.Log("SpaceBar pressed the model will be modified.");
morphModelsPoints("Data/src.obj", "Data/src.csv", "Data/dst.csv",
"Data/res.obj");
//disable old mesh
model.SetActive(false);
OBJLoader obj = new OBJLoader();
model = obj.Load("Data/res.obj");
//displays new mesh
model.SetActive(true);
morphed = true;
}
}
}
The Dll was built with this configuration: Release/Win32.
Here's the dll import settings :
※Please correct me if I am wrong
If I am not mistaken, you can not use 32 dlls in Editor because UNITY is 64bit. If you can just rebuild your dll to 64bit. If you build a standalone then you must set your architecture to x86 instead of x86_64 in Build Settings.
This is my simple code - I'm using Visual Studio 2017, and assume the issue is with the libraries that contain the functions Input."" are not being found.
There is no auto complete, when I start to type Input."" and there are no colours indicating it's a prewritten function. Could anyone help?
I've been stuck trying to figure out how to make this work and I'm completely stalemated (btw even when I type 0.5f it does not colour up like it does when I watch other people code this).
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public float moveSpeed;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetAxisRaw("Horiztonal") > 0.5f)
{
transform.Translate(new Vector3(Input.GetAxisRaw("Horiztonal") * moveSpeed * Time.deltaTime,0f,0f));
}
}
}
I'm trying to learn creating 2D videogames with Unity but i can't compile my script for CharacterMovement because of several errors.
Even creating a new empty script, the compiler says that "Predefined type System.Void is not defined or imported" and i couldn't find online a way to fix this.
This is the empty script :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MyPlayerMovement : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}
And this is the script i'm trying to compile :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour {
public CharacterController2D controller;
public Animator animator;
public float runSpeed = 40f;
float horizontalMove = 0f;
bool jump = false;
bool crouch = false;
// Update is called once per frame
void Update () {
horizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed;
animator.SetFloat("Speed", Mathf.Abs(horizontalMove));
if(horizontalMove == 0)
{
animator.SetBool("Jumping", false);
}
if (Input.GetButtonDown("Jump"))
{
jump = true;
animator.SetBool("Jumping", true);
}
if (Input.GetButtonDown("Crouch"))
{
crouch = true;
animator.SetBool("Crouching", true);
} else if (Input.GetButtonUp("Crouch"))
{
crouch = false;
animator.SetBool("Crouching", false);
}
}
void FixedUpdate ()
{
// Move our character
controller.Move(horizontalMove * Time.fixedDeltaTime, crouch, jump);
jump = false;
}
}
(On my script i get about 60 errors all similar)
change the option in File->BuildSettings->playersettings-api compatibility level to .Net 4X
This happened when I tried to install Microsoft.Toolkit.Uwp.Notification using Install-Package Microsoft.Toolkit.Uwp.Notifications -Version 7.1.2.
Once I do this, I notice a new config file is added to my solution explorer. I have to delete this to fix the error.
Another possible solution for those stumbling across this in the future: Go to Edit->Preferences->External Tools->Regenerate project files to bring back the original CS Project & VS solution files.
That was the only option that worked after trying other common answers like changing API compatibility, upgrading VS, or deleting the project obj folder. I think it broke like that due to me trying to clean out the solution manually and Unity ended up corrupting some packages after I attempted to delete them. So unfortunately it seems you will get this error if you try to do that.
I'm trying to build my first game in Unity 2D.
OS: Windows 10
I reached the moment where I'm supposed to program the controls for a character.
The code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour {
public float moveSpeed;
public float jumpHeight;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(Input.GetKey(KeyCode.W))
{
GetComponend<RigidBody2D> ().velocity = new Vector2 (0, jumpHeight);
}
}
}
Trying to create a build ends with this error text:
> Build failed. MSBuild process could not be started
Please have a look at the screen shot below:
Screenshot
How can I solve this problem?
I'm using unity 5.4.1f1 Personal on windows 10 64bit
I will explain all the steps i did and all the things i tried so far.
Firs time i created a new c# file with the original code:
Now when i press the Escape key it will go back to the editor but will not QUIT the game ! You can't stop the editor play button and quit the game when using [InitializeOnLoad]. To quit the game you can only do it with Build And Run in Standalone mode then you can make Application.Quit();
using UnityEditor;
using UnityEngine;
using System.Collections;
[InitializeOnLoad]
public class FullscreenPlayMode : MonoBehaviour {
//The size of the toolbar above the game view, excluding the OS border.
private static int tabHeight = 22;
static FullscreenPlayMode()
{
EditorApplication.playmodeStateChanged -= CheckPlayModeState;
EditorApplication.playmodeStateChanged += CheckPlayModeState;
EditorApplication.update += Update;
}
static void CheckPlayModeState()
{
if (EditorApplication.isPlaying)
{
FullScreenGameWindow();
}
else
{
CloseGameWindow();
}
}
static EditorWindow GetMainGameView(){
EditorApplication.ExecuteMenuItem("Window/Game");
System.Type T = System.Type.GetType("UnityEditor.GameView,UnityEditor");
System.Reflection.MethodInfo GetMainGameView = T.GetMethod("GetMainGameView",System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
System.Object Res = GetMainGameView.Invoke(null,null);
return (EditorWindow)Res;
}
static void FullScreenGameWindow(){
EditorWindow gameView = GetMainGameView();
Rect newPos = new Rect(0, 0 - tabHeight, Screen.currentResolution.width, Screen.currentResolution.height + tabHeight);
gameView.position = newPos;
gameView.minSize = new Vector2(Screen.currentResolution.width, Screen.currentResolution.height + tabHeight);
gameView.maxSize = gameView.minSize;
gameView.position = newPos;
}
static void CloseGameWindow(){
EditorWindow gameView = GetMainGameView();
gameView.Close();
}
static void Update()
{
if (Input.GetKey (KeyCode.Escape))
{
CloseGameWindow ();
}
}
}
Then since this is not working as i wanted i tried something else.
I deleted the line: [InitializeOnLoad] but didn't change anything else in the rest of the script.
This time after deleting the line [InitializeOnLoad] i dragged the script into the ThirdPersonController.
Now if i will start the game as before form the editor and hit press the escape key it will back to the editor but will not quit the game !
But now if i make in the menu File > Build & Run i will get two errors:
The first error is:
Assets/MyScripts/FullScreenPlayMode.cs(1,7): error CS0246: The type or namespace name `UnityEditor' could not be found. Are you missing a using directive or an assembly reference?
The second error:
Error building Player because scripts had compiler errors
So i went to this solution what suppose to be a solution in this link:
Not working solution
If i move the file script to the EDITOR directory then i can't drag the script to the ThirdPersonController it will throw a message say the script is editor script.
If i tried the second solution in the link:
#if UNITY_EDITOR
// Editor specific code here
#endif
So i did it in the script in the top:
#if UNITY_EDITOR
using UnityEditor;
#endif
And the script file is not in the Editor directory !
This time when i make Build & Run i'm getting a new another error:
Assets/MyScripts/FullScreenPlayMode.cs(34,16): error CS0246: The type or namespace name `EditorWindow' could not be found. Are you missing a using directive or an assembly reference?
Could not find what is this error with the EditorWindow. This error happen when i used the #if and #endif
So in all the ways i tried so far i got another problem.
I might be simplifying your problem but you could simply do this:
void Update()
{
if (Input.GetKey(KeyCode.Escape))
{
#if UNITY_EDITOR
if (EditorApplication.isPlaying)
{
EditorApplication.isPlaying = false;
}
#else
Application.Quit();
#endif
}