Created
December 30, 2019 21:09
-
-
Save dvdfu/c9dfef9a0f63c44b73a3a5f3f38c735b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
// An effect that causes a sprite to be squished vertically or horizontally | |
// e.g. player on jumping, enemies on hit | |
public class Squishable : MonoBehaviour { | |
[SerializeField] [Range(0, 1)] float squishAmount = 0.5f; | |
[SerializeField] [Range(0, 1)] float squishDuration = 0.1f; | |
[SerializeField] SpriteRenderer spriteRenderer; | |
Tween squishTween; | |
public void SquishWide() { | |
squishTween.Start( | |
squishDuration, | |
(float x) => { | |
float squish = 1 + (1 - Easing.CubicIn(x)) * squishAmount; | |
spriteRenderer.transform.localScale = new Vector3(squish, 1 / squish, 1); | |
}, () => { | |
spriteRenderer.transform.localScale = new Vector3(1, 1, 1); | |
} | |
); | |
} | |
public void SquishThin() { | |
squishTween.Start( | |
squishDuration, | |
(float x) => { | |
float squish = 1 + (1 - Easing.CubicIn(x)) * squishAmount; | |
spriteRenderer.transform.localScale = new Vector3(1 / squish, squish, 1); | |
}, () => { | |
spriteRenderer.transform.localScale = new Vector3(1, 1, 1); | |
} | |
); | |
} | |
void Awake() { | |
squishTween = new Tween(this); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment