유니티
17. 유니티 맵(바닥) 시간마다 줄어드는 효과
MJ_119
2023. 6. 23. 18:47
1. 간단한 3D 오브젝트중 큐브를 만들어서 Scale을 조절하자
예. Scale x = 10, y = 0.2, z = 10
2. 간단한 스크립트를 작성해서 Cube 오브젝트에 넣어준다.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Map_Ground : MonoBehaviour
{
private Vector3 initialScale;
public float timer = 5f;
void Start()
{
// 초기 스케일 저장
initialScale = transform.localScale;
}
void Update()
{
// 타이머 업데이트
timer = timer - Time.deltaTime;
// 5초마다 실행
if (timer <= 0f){
// Y값 유지, XZ축의 스케일 감소
transform.localScale = new Vector3(transform.localScale.x - 1f, initialScale.y, transform.localScale.z - 1f);
// 타이머 초기화
timer = 5f;
}
}
}
각자 transform.localScale = new Vector3의(x , y , z)의 Scale을 원하는 만큼 조절해준다.