Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

using UnityEngine.EventSystems is missing

Discussion in 'UGUI & TextMesh Pro' started by NEOF, Jul 12, 2015.

  1. NEOF

    NEOF

    Joined:
    Jun 25, 2013
    Posts:
    9
    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:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.UI;
    4. using UnityEngine.EventSystems;
    5. public class Slot : MonoBehaviour {
    6.     public int slotIndex;
    7.     public Image icon;
    8.     // Use this for initialization
    9.     void Start () {
    10.         icon=this.gameObject.GetComponent<Image>();
    11.     }
    12.  
    13.     // Update is called once per frame
    14.     void Update () {
    15.         if(Control.programSlots[slotIndex]==ProgramRunner.forLoop)
    16.         {
    17.             icon.color=Color.blue;
    18.         }
    19.         if(Control.programSlots[slotIndex]==ProgramRunner.moveBack)
    20.         {
    21.             icon.color=Color.red;
    22.         }
    23.         if(Control.programSlots[slotIndex]==ProgramRunner.moveForward)
    24.         {
    25.             icon.color=Color.yellow;
    26.         }
    27.         if(Control.programSlots[slotIndex]==ProgramRunner.moveLeft)
    28.         {
    29.             icon.color=Color.black;
    30.         }
    31.         if(Control.programSlots[slotIndex]==ProgramRunner.moveRight)
    32.         {
    33.             icon.color=Color.green;
    34.         }
    35.         if(Control.programSlots[slotIndex]==ProgramRunner.blankAction)
    36.         {
    37.             icon.color=Color.white;
    38.         }
    39.  
    40.     }
    41.     public void OnDrop(EventSystems.PointerEventData data)
    42.     {
    43.         Control.programSlots[slotIndex]=Control.selectedCard.action;
    44.         Control.requestSlots[slotIndex]=Control.selectedCard.req;
    45.     }
    46. }
    47.  
    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!
     
    Last edited: Jul 12, 2015
  2. DWilliams

    DWilliams

    Joined:
    Jan 12, 2015
    Posts:
    63
    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)
     
    shrirammvasudevan likes this.
  3. Senshi

    Senshi

    Joined:
    Oct 3, 2010
    Posts:
    557
    @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:

    Code (csharp):
    1. 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.
     
    unity_R_FxE4AcMHOdHg likes this.
  4. NEOF

    NEOF

    Joined:
    Jun 25, 2013
    Posts:
    9
    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.
     
  5. NEOF

    NEOF

    Joined:
    Jun 25, 2013
    Posts:
    9
    Solved. I needed IDropHandler to do what I wanted.
     
  6. henningm

    henningm

    Joined:
    Jul 11, 2016
    Posts:
    18
    I hope I can hang me on your post ??
    I have exactly the same problem only it in different way.


    If am using this:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.UI;
    4. using UnityEngine.EventSystems;
    5. public class Dragable : MonoBehaviour
    6. {
    7.     public void onBeginDrag(EventSystems.PointerEventData data)
    8.     {
    9.         Debug.Log("On Begin Drag");
    10.     }
    11.  
    12.     public void onDrag(EventSystems.PointerEventData data)
    13.     {
    14.         Debug.Log("On Drag");
    15.     }
    16.  
    17.     public void onEndDrag(EventSystems.PointerEventData data)
    18.     {
    19.         Debug.Log("On End Drag");
    20.     }
    21. }
    also
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.UI;
    4. using UnityEngine.EventSystems;
    5. public class Dragable : MonoBehaviour
    6. {
    7.     public void onBeginDrag(PointerEventData data)
    8.     {
    9.         Debug.Log("On Begin Drag");
    10.     }
    11.  
    12.     public void onDrag(PointerEventData data)
    13.     {
    14.         Debug.Log("On Drag");
    15.     }
    16.  
    17.     public void onEndDrag(PointerEventData data)
    18.     {
    19.         Debug.Log("On End Drag");
    20.     }
    21. }
    also
    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4. using UnityEngine.UI;
    5. using UnityEngine.EventSystems;
    6. public class Dragable : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler
    7. {
    8.     public void OnBeginDrag(PointerEventData data)
    9.     {
    10.         Debug.Log("On Begin Drag");
    11.     }
    12.  
    13.     public void OnDrag(PointerEventData data)
    14.     {
    15.         Debug.Log("On Drag");
    16.     }
    17.  
    18.     public void OnEndDrag(PointerEventData data)
    19.     {
    20.         Debug.Log("On End Drag");
    21.     }
    22. }
    23.  
    the type or namespace name eventsystems could not be found. Are you missing assembly reference ?

    Any idea how I can fix it ??
     
    Last edited: Nov 22, 2018
  7. henningm

    henningm

    Joined:
    Jul 11, 2016
    Posts:
    18
    Solved;
    After many hours atlast I found it out how to do it. :D

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.UI;
    4. using UnityEngine.EventSystems;
    5. public class Dragable : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler
    6. {
    7.     public void OnBeginDrag(PointerEventData data)
    8.     {
    9.         Debug.Log("On Begin Drag");
    10.     }
    11.  
    12.     public void OnDrag(PointerEventData data)
    13.     {
    14.         Debug.Log("On Drag");
    15.         this.transform.position = data.position;
    16.     }
    17.  
    18.     public void OnEndDrag(PointerEventData data)
    19.     {
    20.         Debug.Log("On End Drag");
    21.     }
    22. }