포인트 같은거 자동으로 움직이게 하는 코드
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Plusing : MonoBehaviour
{
public Transform TargetObject;
public float plusSize = 0.025f;
private bool coroutineAllowed;
// Start is called before the first frame update
void Start()
{
TargetObject = transform;
coroutineAllowed = true;
}
void OnMouseOver()
{
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 + plusSize, 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, Mathf.SmoothStep(0f, 1f, i)))
);
yield return new WaitForSeconds(0.015f);
}
for (float i = 0f; i < 1f; i += 0.1f)
{
transform.localScale = new Vector3(
(Mathf.Lerp(TargetObject.localScale.x, TargetObject.localScale.x - plusSize, 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, Mathf.SmoothStep(0f, 1f, i)))
);
yield return new WaitForSeconds(0.015f);
}
coroutineAllowed = true;
}
}