Advertisement
medvedya

EXAMPLE_monster

Dec 21st, 2014
770
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.45 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement