2022년 6월 8일 수요일

Unity Plusing Object(움찔움찔하는기능)

 

포인트 같은거 자동으로 움직이게 하는 코드


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;
    }

}




댓글 없음:

댓글 쓰기

git rejected error(feat. cherry-pick)

 문제 아무 생각 없이 pull을 받지않고 로컬에서 작업! 커밋, 푸시 진행을 해버렷다. push에선 remote와 다르니 당연히 pull을 진행해라고 하지만 로컬에서 작업한 내용을 백업하지 않고 진행하기에는 부담스럽다(로컬작업 유실 가능성) 해결하려...