Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[SOLVED]Always Select Last added object

Discussion in 'UGUI & TextMesh Pro' started by mitaywalle, Dec 5, 2014.

  1. mitaywalle

    mitaywalle

    Joined:
    Jul 1, 2013
    Posts:
    247
    Ive created class of objects, that can be dragged, registered pointer events through Interfaces, there is important part of code:

    Code (CSharp):
    1. using System.Collections.Generic;
    2. using UnityEngine;
    3. using System.Collections;
    4. using UnityEngine.Events;
    5. using UnityEngine.EventSystems;
    6.  
    7. public class CollectObject : MonoBehaviour , IPointerDownHandler,IDragHandler,IPointerUpHandler
    8. {
    9.     public void OnPointerDown(PointerEventData eventData)
    10.     {
    11.         //Debug.Log(EventSystem.current.name);
    12.         //EventSystem.current.SetSelectedGameObject(gameObject, null);
    13.         //Debug.Log(EventSystem.current.currentSelectedGameObject);
    14.         //Debug.Log("MouseDown");
    15.         StartCoroutine(StartDrag());
    16.     }
    17.     public void OnDrag(PointerEventData eventData)
    18.     {
    19.         //Debug.Log("Drag");
    20.         StartCoroutine(MoveDrag());
    21.     }
    22.     public void OnPointerUp(PointerEventData eventData)
    23.     {
    24.         //Debug.Log("MouseUp");
    25.         StartCoroutine(StopDrag());
    26.     }
    27. }
    As you can see i've tried directly set active object, but log and game say that object always last added / configurated.

    Click works OK but always with last object, i cant undersand - why?

    Big thanks to everyone who answers.
     
  2. mitaywalle

    mitaywalle

    Joined:
    Jul 1, 2013
    Posts:
    247
  3. mitaywalle

    mitaywalle

    Joined:
    Jul 1, 2013
    Posts:
    247
    Reason was in UIImage Component wich was with Alpha = 0f & Large Size