using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UpDownMove : MonoBehaviour
{
Transform TargetObject;
float plusSize = 0.015f;
float tempo = 0.025f;
private bool coroutineAllowed;
// Start is called before the first frame update
private void Start()
{
TargetObject = transform;
coroutineAllowed = true;
}
// Update is called once per frame
void Update()
{
if (coroutineAllowed)
{
StartCoroutine(StartPlusing());
}
}
private IEnumerator StartPlusing()
{
coroutineAllowed = false;
for (float i = 0f; i < 1f; i += 0.1f)
{
transform.localScale = new Vector3(
(Mathf.Lerp(TargetObject.localScale.x, TargetObject.localScale.x , Mathf.SmoothStep(0f, 1f, i))),
(Mathf.Lerp(TargetObject.localScale.y, TargetObject.localScale.y + plusSize, Mathf.SmoothStep(0f, 1f, i))),
(Mathf.Lerp(TargetObject.localScale.z, TargetObject.localScale.z + plusSize * 0.1f, Mathf.SmoothStep(0f, 1f, i)))
);
yield return new WaitForSeconds(tempo);
}
for (float i = 0f; i < 1f; i += 0.1f)
{
transform.localScale = new Vector3(
(Mathf.Lerp(TargetObject.localScale.x, TargetObject.localScale.x , Mathf.SmoothStep(0f, 1f, i))),
(Mathf.Lerp(TargetObject.localScale.y, TargetObject.localScale.y - plusSize, Mathf.SmoothStep(0f, 1f, i))),
(Mathf.Lerp(TargetObject.localScale.z, TargetObject.localScale.z - plusSize*0.1f, Mathf.SmoothStep(0f, 1f, i)))
);
yield return new WaitForSeconds(tempo);
}
coroutineAllowed = true;
}
}
댓글 없음:
댓글 쓰기