본문 바로가기
유니티강좌

오브젝트(2D 캐릭터) 크기조절 구현(유니티 2D 기초 강좌) - Transform localScale을 이용한 사이즈 축소, 확대. Unity C# Script Tutorial

by Ncube 2020. 11. 27.

 

 

 

유니티와 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);
        }
    }
}

 

댓글