Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- THIS CODE REQUIRES A CHARACTER CONTROLLER FROM WHICH YOU GET THE OBJECTS VELOCITY AND CHECK WETHER THE OBJECT IS GROUNDED.
- */
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class SqueezeStretch : MonoBehaviour
- {
- public Transform target;
- private CharacterController2D _Controller;
- public bool canStretch = true;
- [Space(5)]
- [Header("Lerp & Stretch")]
- [SerializeField] private float _lerpTime = .05f;
- [SerializeField] private Vector2 _xStretch = new Vector2(0.5f, 1.5f);
- [SerializeField] private Vector2 _yStretch = new Vector2(1.5f, 0.5f);
- private void Start()
- {
- _Controller = GetComponent<CharacterController2D>();
- }
- // Update is called once per frame
- void Update()
- {
- if (target.localScale.x != 1|| target.localScale.y != 1)
- {
- target.localScale = new Vector2(Mathf.Lerp(target.localScale.x, 1, _lerpTime), Mathf.Lerp(target.localScale.y, 1, _lerpTime));
- }
- if (Input.GetButtonDown("Jump") && !canStretch)
- {
- target.localScale = new Vector2(_xStretch.x, _xStretch.y);
- canStretch = true;
- }
- else if (_Controller.grounded && canStretch)
- {
- if (_Controller.velocity.y < -8f)
- {
- target.localScale = new Vector2(_yStretch.x ,_yStretch.y);
- }
- canStretch = false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement