daily pastebin goal
42%
SHARE
TWEET

EXAMPLE_createSpriteDeformer

medvedya Dec 20th, 2014 655 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using UnityEngine;
  2. using System.Collections;
  3. using Medvedya.SpriteDeformerTools;
  4.  
  5. public class EXAMPLE_createSpriteDeformer : MonoBehaviour
  6. {
  7.  
  8.     public Sprite sprite;
  9.     public Material material;
  10.     SpriteDeformerStatic mySprite;
  11.     private SpritePoint centerPoint;
  12.     void Start () {
  13.         mySprite = gameObject.AddComponent<SpriteDeformerStatic>();
  14.         mySprite.sprite = sprite;
  15.         mySprite.referenceMaterial = material;
  16.         mySprite.SetRectanglePoints();
  17.  
  18.         centerPoint = new SpritePoint(0.5f, 0.5f);
  19.         mySprite.AddPoint(centerPoint);
  20.        
  21.         Bounds b = mySprite.bounds;
  22.         foreach (var item in mySprite.points)
  23.         {
  24.             b.Encapsulate((Vector3)mySprite.SpritePositionToLocal(item.spritePosition));
  25.         }
  26.         mySprite.bounds = b;
  27.         mySprite.UpdateMeshImmediate();
  28.         }
  29.    
  30.     void Update()
  31.     {
  32.         centerPoint.offset2d =
  33.             new Vector2(Mathf.Cos(Time.time) * 0.3f,
  34.                 Mathf.Sin(Time.time) * 0.3f);
  35.  
  36.         mySprite.dirty_offset = true;
  37.        
  38.         float t = Mathf.PingPong(Time.time,1);
  39.         centerPoint.color = Color.Lerp(Color.blue, Color.red,t);
  40.         mySprite.dirty_color = true;
  41.     }
  42. }
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
 
Top