using UnityEngine;
|
using System.Collections;
|
|
public class PingPongScale:MonoBehaviour {
|
|
public Transform reference;
|
public Vector3 amplitue;
|
public float speed;
|
|
Vector3 referenceScale = Vector3.zero;
|
|
void OnEnable() {
|
referenceScale = reference == null ? this.transform.localScale : reference.localScale;
|
}
|
|
float x = 0f;
|
float y = 0f;
|
float z = 0f;
|
void LateUpdate() {
|
|
if(Mathf.Abs(amplitue.x) > 0.001f) {
|
x = referenceScale.x - amplitue.x * 0.5f + Mathf.PingPong(Time.time * speed,amplitue.x);
|
}
|
else {
|
x = referenceScale.x;
|
}
|
|
if(Mathf.Abs(amplitue.y) > 0.001f) {
|
y = referenceScale.y - amplitue.y * 0.5f + Mathf.PingPong(Time.time * speed,amplitue.y);
|
}
|
else {
|
y = referenceScale.y;
|
}
|
|
if(Mathf.Abs(amplitue.z) > 0.001f) {
|
z = referenceScale.z - amplitue.z * 0.5f + Mathf.PingPong(Time.time * speed,amplitue.z);
|
}
|
else {
|
z = referenceScale.z;
|
}
|
|
this.transform.localScale = new Vector3(x,y,z);
|
}
|
}
|