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

Taking behaviors from a class with PointEventData arguments

Discussion in 'Scripting' started by prototyped, Jan 8, 2019.

  1. prototyped

    prototyped

    Joined:
    May 31, 2013
    Posts:
    18
    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


    Code (CSharp):
    1.   public void OnBeginDrag(PointerEventData eventData){
    2.             Debug.Log ("OnBeginDrag");
    3.             returnedToParent = this.transform.parent;
    4.             Debug.Log (returnedToParent);
    5.             this.transform.SetParent (this.transform.parent.parent);
    6.  
    7.             //this alows the card to know when its in the drop zone
    8.             //your mouse is always raycasting to know where it is but we block it so that
    9.             //when getting a card the card isnt constantly consuming the raycasts so it doesnt see the mouse
    10.             //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
    11.             //just go into the code, but thts just preference
    12.             GetComponent<CanvasGroup>().blocksRaycasts = false;
    13.         }
    monk card class


    Code (CSharp):
    1. public class SolutMonkActive :  MonoBehaviour{
    2.      
    3.             //newdd code goes here....
    4.  
    5.     }