- Home /
OnMouseEnter and gameObject.name with C#
Hello, I'm trying to print the name of the game object that i am flying over with my mouse in C#, likes this JS code :
function OnMouseEnter() {
Debug.Log(gameObject.name + " OnMouseOver");
}
thanks
also, in the documentation(file:///Applications/Unity/Unity.app/Contents/Documentation/Documentation/ScriptReference/$$anonymous$$onoBehaviour.On$$anonymous$$ouseOver.html) on the top right off the snippet is an option that allows you to change the language for the snippet(JS/C#/Boo)
Answer by Mike 3 · Jun 16, 2010 at 10:41 AM
Should just be this:
void OnMouseEnter() {
Debug.Log(gameObject.name + " OnMouseOver");
}
Edit:
And just in case you want a full class (change YourFileName to the filename you made in the project view):
using UnityEngine;
public class YourFileName : MonoBehaviour { void OnMouseEnter() { Debug.Log(gameObject.name + " OnMouseOver"); } }
Your answer
![](https://koobas.hobune.stream/wayback/20220613062230im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Highlighting Objects Behind Other Objects 0 Answers
Carrying Objects OnMouseOver 0 Answers
How can I make a section of an object react to my mouse being on it or my mouse clicking on it? 0 Answers
Illuminating a 3D object's edges OnMouseOver (script in c#)? 1 Answer
OnMouseOver Distance Measuring 1 Answer