using UnityEngine.EventSystems is missing

Hi, I have a problem. I have Unity 5.1.1 and when I am trying to have “using UnityEngine.EventSystems” the reference is missing. I am trying to use it to get the object being dropped on ondrop function. I couldn’t find a lot of info about this issue. Does anyone know how to fix that?
Here is the code:

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class Slot : MonoBehaviour {
    public int slotIndex;
    public Image icon;
    // Use this for initialization
    void Start () {
        icon=this.gameObject.GetComponent<Image>();
    }
  
    // Update is called once per frame
    void Update () {
        if(Control.programSlots[slotIndex]==ProgramRunner.forLoop)
        {
            icon.color=Color.blue;
        }
        if(Control.programSlots[slotIndex]==ProgramRunner.moveBack)
        {
            icon.color=Color.red;
        }
        if(Control.programSlots[slotIndex]==ProgramRunner.moveForward)
        {
            icon.color=Color.yellow;
        }
        if(Control.programSlots[slotIndex]==ProgramRunner.moveLeft)
        {
            icon.color=Color.black;
        }
        if(Control.programSlots[slotIndex]==ProgramRunner.moveRight)
        {
            icon.color=Color.green;
        }
        if(Control.programSlots[slotIndex]==ProgramRunner.blankAction)
        {
            icon.color=Color.white;
        }

    }
    public void OnDrop(EventSystems.PointerEventData data)
    {
        Control.programSlots[slotIndex]=Control.selectedCard.action;
        Control.requestSlots[slotIndex]=Control.selectedCard.req;
    }
}

And here is the error: Assets/Slot.cs(41,28): error CS0246: The type or namespace name `EventSystems’ could not be found. Are you missing a using directive or an assembly reference?

Help Please!

Since you’ve already included the UnityEngine.EventSystems namespace in your script, there’s no need to specify the namespace for PointerEventData although you still can but you have to specify the entire UnityEngine.EventSystems. namespace not just EventSystems.

So

public void OnDrop(EventSystems.PointerEventData data)

should be

public void OnDrop(PointerEventData data) or public void OnDrop(UnityEngine.EventSystems.PointerEventData data)

1 Like

@DWilliams is correct. To add to that though, if you really want to refer to EventSystems, but not the entire UnityEngine.[...] path, you could use a namespace alias:

using EventSystems = UnityEngine.EventSystems;

This would make your existing code work. There isn’t really a need for that in this case though, but figured I’d throw it out there regardless.

1 Like

I have another problem there. If I do just public void OnDrop(PointerEventData data) - then I can not select the method OnDrop from the list on my trigger event component. What I need basically is to have OnDrop method called while drop event is triggered and I want to pass the object that was dropped to the OnDrop method somehow. Maybe you guys can help me with other solution. I’ve tried all 2 suggested here and still can’t use the function in trigger event.

Solved. I needed IDropHandler to do what I wanted.

I hope I can hang me on your post ??
I have exactly the same problem only it in different way.

If am using this:

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class Dragable : MonoBehaviour
{
    public void onBeginDrag(EventSystems.PointerEventData data)
    {
        Debug.Log("On Begin Drag");
    }

    public void onDrag(EventSystems.PointerEventData data)
    {
        Debug.Log("On Drag");
    }

    public void onEndDrag(EventSystems.PointerEventData data)
    {
        Debug.Log("On End Drag");
    }
}

also

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class Dragable : MonoBehaviour
{
    public void onBeginDrag(PointerEventData data)
    {
        Debug.Log("On Begin Drag");
    }

    public void onDrag(PointerEventData data)
    {
        Debug.Log("On Drag");
    }

    public void onEndDrag(PointerEventData data)
    {
        Debug.Log("On End Drag");
    }
}

also

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class Dragable : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler
{
    public void OnBeginDrag(PointerEventData data)
    {
        Debug.Log("On Begin Drag");
    }

    public void OnDrag(PointerEventData data)
    {
        Debug.Log("On Drag");
    }

    public void OnEndDrag(PointerEventData data)
    {
        Debug.Log("On End Drag");
    }
}

the type or namespace name eventsystems could not be found. Are you missing assembly reference ?

Any idea how I can fix it ??

Solved;
After many hours atlast I found it out how to do it. :smile:

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class Dragable : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler
{
    public void OnBeginDrag(PointerEventData data)
    {
        Debug.Log("On Begin Drag");
    }

    public void OnDrag(PointerEventData data)
    {
        Debug.Log("On Drag");
        this.transform.position = data.position;
    }

    public void OnEndDrag(PointerEventData data)
    {
        Debug.Log("On End Drag");
    }
}