Advertisement
fivearchers

Scale by Curve script for Unity3D

Oct 22nd, 2013
941
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.00 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. //script to apply scaling over time based on a curve
  4. //Quentin Preik - 2012/10/22
  5. //@fivearchers
  6. public class CurveScale : MonoBehaviour {
  7.  
  8.     public AnimationCurve scaleCurve;   //Curve to scale with - usually cover 0 to 1 on both axis
  9.     public Vector3 movement;            //this is the scaling amount - it is additive, so if you say 0,2,0 - at 1 on the curve
  10.                                         // your object would be 2x as big on the Y axis, and the same size on x and z
  11.    
  12.     public float scaleRate;             //How fast to scale:  1=1s, 2=0.5s, 0.5=2s
  13.     public float curvePos;              //Use this as an offset, so at 0.5 it would start halfway thru the curve
  14.     public bool loop=true;              //Whether to loop or not
  15.     Vector3 localstart;
  16.    
  17.     void Start () {
  18.         localstart=transform.localScale;
  19.     }
  20.    
  21.  
  22.     void Update () {
  23.         if (curvePos!=1||!loop){
  24.             curvePos+=scaleRate*Time.deltaTime;
  25.             if (curvePos>1f){curvePos=curvePos-1f;}
  26.             transform.localScale=localstart+movement*scaleCurve.Evaluate(curvePos);
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement