- Home /
Getting on drag functions into other classes
So Im making a card game and I have a class that holds all the basic drag functions that every card will use from the Unitys dragging interface. What Im trying to do is not have that class be attached to any object, instead take the onDrag etc. functions from the class and put it in every individual cards class. Im running into an issues where I need the PointerEventData that comes with every drag function so I cant really call the function separately. Is there a way I can do this or should i just uses the class with the interface and give it to every card with its unique properties?
newdd class
public void OnBeginDrag(PointerEventData eventData){
Debug.Log ("OnBeginDrag");
returnedToParent = this.transform.parent;
Debug.Log (returnedToParent);
this.transform.SetParent (this.transform.parent.parent);
//this alows the card to know when its in the drop zone
//your mouse is always raycasting to know where it is but we block it so that
//when getting a card the card isnt constantly consuming the raycasts so it doesnt see the mouse
//also, you can do this in the UI but doing it this way will make it so you dont have to remeber to set things
//just go into the code, but thts just preference
GetComponent<CanvasGroup>().blocksRaycasts = false;
}
monk card class
public class SolutMonkActive : MonoBehaviour{
//newdd code goes here....
}
Answer by Magso · Jan 08, 2019 at 10:05 PM
You're technically asking can you execute a script from another script rather than just a class as OnBeginDrag is function called within unity. You could call a function from every object with OnBeginDrag with newdd having NewFunction().
public void OnBeginDrag(PointerEventData eventData){
otherObject.GetComponent<newdd>().NewFunction();
}
If you store what you need from PointerEventData into variables in newdd so you can access the data, you can use OnBeginDrag on all of them.