1
votes

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.

2

2 Answers

0
votes

To solve that you can do the following:

  1. Close Unity and Visual Studio.
  2. Open Unity.
  3. 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

0
votes

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.