medvedya

EXAMPLE_monster

Dec 21st, 2014
559
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using Medvedya.SpriteDeformerTools;
  5.  
  6. public class EXAMPLE_monster : MonoBehaviour
  7. {
  8.  
  9.     SpriteDeformerAnimation spriteDeformerAnimation;
  10.     List<SpritePoint> footPoints = new List<SpritePoint>();
  11.     public Vector2 hitOffset = new Vector2(0, -0.1f);
  12.     void Start()
  13.     {
  14.         spriteDeformerAnimation = GetComponent<SpriteDeformerAnimation>();
  15.         foreach (var point in spriteDeformerAnimation.points)
  16.         {
  17.             if (point.name == "foot")
  18.             {
  19.                 footPoints.Add(point);
  20.                 spriteDeformerAnimation.notAnimatedPoints.Add(point);
  21.             }
  22.         }
  23.     }
  24.     void Update()
  25.     {
  26.         transform.position = (Vector2)Camera.main.ScreenToWorldPoint(Input.mousePosition);
  27.         foreach (var point in footPoints)
  28.         {
  29.             Vector2 footGlobalPos = spriteDeformerAnimation.SpritePositionToGlobal(point.spritePosition);
  30.             Vector2 orign = new Vector2(footGlobalPos.x, transform.position.y);
  31.             RaycastHit2D hit = Physics2D.Raycast(orign, -Vector2.up);
  32.             if (hit.collider != null)
  33.             {
  34.                 Vector2 newOffset = spriteDeformerAnimation.GlobalPositionToSpritePosition(hit.point + hitOffset) - point.spritePosition;
  35.                 point.offset2d = newOffset;
  36.                 spriteDeformerAnimation.dirty_offset = true;
  37.             }
  38.         }
  39.     }
  40. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×