유니티와 C# (unity transform scale) 튜토리얼 유니티의 Transform요소 중 localScale을 이용한 캐릭터 사이즈 축소, 확대
- Header : 제목, 설명 문구
- SerializeField : Private변수를 인스펙터창에 노출
- Range : 범위지정 (Min, Max)
[CODE]
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ScaleScript : MonoBehaviour
{
[Header("크기속도 조절")]
[SerializeField] [Range(1f, 5f)] float scaleSpeed = 1f;
void Update()
{
//크기(축소 C / 확대 V)
if (Input.GetKey(KeyCode.C))
{
transform.localScale = new Vector3
(transform.localScale.x - 1f * scaleSpeed * Time.deltaTime,
transform.localScale.y - 1f * scaleSpeed * Time.deltaTime, 0);
}
if (Input.GetKey(KeyCode.V))
{
transform.localScale = new Vector3
(transform.localScale.x + 1f * scaleSpeed * Time.deltaTime,
transform.localScale.y + 1f * scaleSpeed * Time.deltaTime, 0);
}
}
}
댓글