I'm a Unity beginner ,so right now I'm doing some small projects by watching some tutorials on youtube.
But, after looking at one tutorial that used the "OnTriggerEnter" function with the attribute "Collider". I realized that my editor didn't recognize "Collider" so I couldn't use "OnTriggerEnter".
I searched on the internet, but coudln't find any answer related to my question.
It's the first time, it's happened to me so I don't really know how to solve this problem...
Here's my little code, I'm just trying to move something when my player enters in a zone.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Trigger : MonoBehaviour
{
public bool opening = false;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
// OnTriggerEnter is called when something enter in the trigger
void OnTriggerEnter(Collider obj)
{
if(obj.transform.name == "Player")
{
opening = true;
}
}
}
So, as I said, my unity editor which is Microsoft visual studio does not detect "Collider" (I don't have the possibility to pre-fill by pressing enter for example) and the color is white and not blue like "true" for example.
So because of that I can't move forward with the project, and I'd like to know what to do so that my editor recognizes "Collider" and I can make my project work!
Thank you in advance for your answers.
To solve that you can do the following:
Close Unity and Visual Studio.
Open Unity.
Open Visual Studio from Unity (Assets => Open C# Project).
If that doesn't work you need to check your current editor in:
Edit => Preferences => External Tools => External Script Editor
Visual Studio always have some errors like missing dependencies and stuff. I would recommend using Visual Studio Code application. Just like #Jack has explained. Browse to Edit => Preferences => External Tools => External Script Editor and change your script editor to Visual Studio Code and then try again.
Related
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
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
I just started learning c# for unity today and at my 3rd line of code I run into a problem:
My VSCode doesn't "recognize" the GameObject variable. The autocomplete menu doesnt show it and if I hard-write it, it doesnt get coloured.
Im following this tutorial and I dont wanna keep going without solving this.
Its worth clarifying that I didnt install anything other than VSCode and Unity 2019.3.2 and maybe I need a some extension?
Here's the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour
{
public int health = 5;
public float fhealth = 5.0;
public GameObject player;
}
Visual Studio Code normally doesnt autocomplete Classes if not installed with Unity Package Manager. So, if you dont have any compiler errors you could just continue without autocomplete.
I am trying out Unity for my Game Design course, but I can't seem to get the code to work. I suspect it is because Visual Studio (which I write my code on) is not connecting to Unity properly, and here's why I think this:
For one thing, whenever I try to put the code on an object, it prints out this error:
Can't add script behaviour CallbackExecutor. The script needs to derive from MonoBehaviour!
This is despite the fact that nowhere is the code called CallbackExecutor, and the script apparently does derive from MonoBehaviour.
Second, when I load up the code onto Visual Studio, I get this error message:
C:\Users\cemya\Documents\D&D Roguelight Project\Assembly-CSharp.csproj : error : The project file could not be loaded. Could not find file 'C:\Users\cemya\Documents\D&D Roguelight Project\Assembly-CSharp.csproj'. C:\Users\cemya\Documents\D&D Roguelight Project\Assembly-CSharp.csproj
The problem is I don't know why it's not connecting. There's no option to import the package (which implies it's already imported), and I do have a package for Unity.
I'm using Visual Studios 2017 (specifically, I'm using the 2d setup most of the time), Unity version 2018.2.4f1, and the package is called Visual Studio 2017 Tools for Unity [Experimental], which is what was automatically downloaded when I began to set up coding for Unity. Since I got this version automatically, I believe that this should be a common problem, but I can't seem to find real answers on it (I even asked on the Unity forms themselves!)
I can show you the code if you think that would help.
UPDATE: I have just updated Unity to 2018.2.5f1 and tested it with the code that has actual code. All that happened is that the name for the error message is different:
Can't add script behaviour TMP_CoroutineTween. The script needs to derive from MonoBehaviour!
Also, here is the code for the one I'm testing, if it helps:
public class RollScript : MonoBehaviour
{
Random rand = new Random();
int r = 20;
int m = 5;
// Use this for initialization
void Start ()
{
int rolling = DieRoll(r, m);
print(rolling);
}
// Update is called once per frame
void Update ()
{
}
int DieRoll (int roll, int mod)
{
int get = rand.next(1, roll);
int result = get + mod;
return result;
}
}
UPDATE 2: I have checked with visual studio, and the error message there isn't there anymore, so that's an improvement.
UPDATE 3: I have created a new project and I have not run into issues there. I guess the problem was the code's connection to older editions.
This Can't add script behaviour TMP_CoroutineTween. The script needs to derive from MonoBehaviour! error has been mentioned in a few places on the internet, but with no satisfactory answers. This seems to be the only StackOverflow question about it.
I suspect it happens when there are un-fixed compile-time errors while you're adding a script to a GameObject. I had this problem just now, and after I fixed the errors, I was able to add the script. However, I tried to confirm this by adding a syntax error and then adding a script, but I still didn't get the Can't add script behavior error. So that's odd, but if you're encountering that error, I suggest fixing any compile-time errors and see if that works. (Whether it works or not, please reply to this question with the result.)
I have just started using Parse.com On Unity 5.0.0fb, and after getting my application to work with Parse on Unity Editor I decided to try it on my Mobile to find nothing works. I have checked the APK and Parse is inside it but when I try anything it does not work.
I have tested this with a Test APK with nothing but parse and the test script attached to a button and it also does not work.
using UnityEngine;
using System.Collections;
using Parse;
public class ScriptTest : MonoBehaviour {
public UnityEngine.UI.Text Mytext;
string mytext;
// Use this for initialization
public void MySpecial () {
ParseObject testObject = new ParseObject("TestObject");
testObject["foo"] = "bar";
testObject.SaveAsync();
mytext = "Saved";
Mytext.text = mytext;
Debug.Log (mytext);
}
// Update is called once per frame
void Update () {
}
}
It will not do anything the button will click it will say saved on my text but when I check parse TestObject nothing will be there. Is there something im missing in my build?
I have made sure stripping is also disabled.
This works 100% in editor just not in Android I have no idea or way to test iOS.
I have the exact same problem, using Unity 5.1 and Parse Unity SDK 1.5.1. It works perfectly in the editor but not on Android.
Here's my code :
ParseObject _localPlayer = new ParseObject();
Task query = _localPlayer.SaveAsync();
while (!query.IsCompleted)
yield return null;
if (!query.IsFaulted && !query.IsCanceled)
{
Debug.Log ("Player successfully created!");
}
else
{
Debug.Log("Failed to create player...");
}
The task generated with the SaveAsync() request doesn't seem to end at all (isCompleted is never true) so it becomes an infinite loop, and the actual cloud operation is not performed (no trace on the Parse dashboard). There doesn't seem to be any exception thrown and the device log doesn't show anything.
I'm really stuck at this point and haven't be able to find any solution anywhere on the web so far. :(
Using Parse SDK 1.3.2 "fixes" the issue.
-> https://parse.com/downloads/windows/Parse/1.3.2
Looks like a big fat regression. ;)
Going back to Parse Unity SDK 1.3.2 worked for me.
LogOutAsync() had to be replaced with LogOut(), but that was the only change I had to make in my code.
The solution to this problem is to reimport project settings from their blank project. It will fix any build problems you have.
The bug report, for those who would like to be kept informed:
https://developers.facebook.com/bugs/1623483557935932/