변수

- 박스와 비슷한 개념

- 이름이 있음

- 데이터가 들어있음

- 특정 타입이 있음

ex)

타입 변수이름 = 값;

int hitPoints = 20;

float speed = 3.8f;

bool isAlive = true;

string myName = "Rick";

 

장점

1. 가독성 - 한 곳에 모아둬서 보기 편함

2. 조작이 쉬움 - 자동완성, 한 번 선언하면 여러 곳에서 사용 가능

 

 

실행

공중으로 발사

 

Mover.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Mover : MonoBehaviour
{
    // 선언
    float xValue = 0f;
    float yValue = 0.01f;
    float zValue = 0f;

    void Start()
    {

    }

    void Update()
    {
        // 프레임 당 값만큼 움직임
        // 변수 자동완성 됨 - 편리
        transform.Translate(xValue, yValue, zValue);
    }
}

+ Recent posts