- Home /
Cannot set currentSelectedObject in OnMouseDown
Hello,
I have this code :
public class MyClass : MonoBehaviour
{
void Start () {
}
// Update is called once per frame
void Update () {
}
private void OnMouseOver()
{
}
private void OnMouseExit()
{
}
private void OnMouseDown()
{
EventSystem.current.SetSelectedGameObject(this.gameObject);
}
}
When I call EventSystem.current.currentSelectedGameObject: in OnMouseDown, it returns the correct object ; in Update, it returns null.
However, if I set the selectedGameObject in OnMouseOver or OnMouseExit instead of OnMouseDown (and using the appropriate input accordingly), it is correctly set when accessed in Update.
I cannot understand why, in the particular context above, SetSelectedGameObject is somehow not persistent, and the currentSelectedObject seems to be set to null at the end of the OnMouseDown function.
Thanks you very much in advance for your help :)
Your answer
Follow this Question
Related Questions
Why am I not able to drag a script into another script's Game Manager anymore? 1 Answer
Network Instantiate WITHOUT inspector? 0 Answers
Checking if Image Effects exist in the project 0 Answers
Appear a text at start in the center of the screen 1 Answer
Using For Loop index as if statement parameter within the loop 0 Answers