I am working on game in which user can drag objects to desire position. After dropping at desired position
I want to disable the onDrag method. But I am unable to achieve this functionality. Kindly help me!
Thanks in Advance.
public void OnDrag()
{
Vector3 pos = Camera.main.ScreenToWorldPoint (Input.mousePosition);
pos.z = 0;
gameObject.transform.position = pos;
if(isNearToDesiredPos())
enabled = false;
}
Note: “isNearToDesiredPos” is returning true on desired position.
fafase
August 26, 2015, 7:18am
2
You can’t unregister it as it is done internally. you can prevent running the code.
public void OnDrag()
{
if(isDropped) return;
Vector3 pos = Camera.main.ScreenToWorldPoint (Input.mousePosition);
pos.z = 0;
gameObject.transform.position = pos;
if(isNearToDesiredPos())
enabled = false;
}
isDropped is set when you drop the object. I would guess it might go with enabled = false;
I know maybe is too late. But it would be the best solution.
If the Button or Gameobject has an image component you can use:
.GetComponent<Image>().raycastTarget = boolValue
as you want like button.interactable = boolValue.
Using This
GetComponent().enabled=true;