SHARE
TWEET

Grabbing a Sprite

npgdev Oct 31st, 2015 105 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  Sprite newHandSprite1;
  2.     GameObject newSpritePosition;
  3.     LayerMask YourLayerMask;
  4.         void Start () {
  5.        
  6.         }
  7.        
  8.         void Update () {
  9.  
  10.         //Choosing Any input, you can do a collision or whatever!
  11.         if (Input.GetKey(KeyCode.Space))
  12.         {
  13.  
  14.             //Do your finding , I love Overlapcircle because of simplicity
  15.  
  16.             Collider2D hit = Physics2D.OverlapCircle(transform.position,1,YourLayerMask);
  17.             // Now do this
  18.            if (hit)
  19.            {
  20.  
  21.                newHandSprite1 = hit.gameObject.GetComponent<SpriteRenderer>().sprite;
  22.                Destroy(hit.gameObject);
  23.                newSpritePosition.GetComponent<SpriteRenderer>().sprite = newHandSprite1;
  24.  
  25.            }
  26.  
  27.  
  28.         }
  29.  
  30.        
  31.         }
  32.  
  33.  
  34.    
  35. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top