변수사용 4

2.5.5 for 문으로 반복하기

2.5.5 for문으로 반복하기 반복 횟수를 지정하면 자동으로 반복 횟수만큼 처리를 반복하는 for문을 사용 for (반복 횟수) { 처리 } for (변수 초기화; 반복 조건식; 변수 갱신) { 처리 } ① i 변수를 0으로 초기화 ② 반복 조건(i < 5)을 만족하면 ③, 만족하지 않으면 반복문을 종료 ③ Console 창에 i 값을 출력 ④ i를 증가시킴 (i 값을 1 증가) ⑤ ②로 돌아감 ※ for 문 사용하기 using System.Collections; using System.Collections.Generic; using UnityEngine; // 유니티가 동작하는데 필요한 기능 제공 public class test : MonoBehaviour { // Start is called bef..

2.5 제어문 사용하기

2.5.1 if문으로 조건 분기하기 특정한 조건이 맞을 때만 스크립트를 실행하고 싶다면 if문을 사용 if문은 관계연산자를 사용해서 조건식을 사용 ※ if 문 사용하기 using System.Collections; using System.Collections.Generic; using UnityEngine; // 유니티가 동작하는데 필요한 기능 제공 public class test : MonoBehaviour { // Start is called before the first frame update void Start() { int herbNum = 1; if (herbNum == 1) { Debug.Log("체력을 50 회복"); } } } 결과값 보기 더보기 체력을 50 회복 herbNum = 5; ..

2.4.2 변수와 연산

2.4.2 변수와 연산 using System.Collections; using System.Collections.Generic; using UnityEngine; // 유니티가 동작하는데 필요한 기능 제공 public class test : MonoBehaviour { // Start is called before the first frame update void Start() { int answer; answer = 1 + 2; Debug.Log(answer); } } 결과값 보기 더보기 3 ※ 사칙 연산하기 using System.Collections; using System.Collections.Generic; using UnityEngine; // 유니티가 동작하는데 필요한 기능 제공 publi..

2.4.1 변수 사용하기

using System.Collections; using System.Collections.Generic; using UnityEngine; // 유니티가 동작하는데 필요한 기능 제공 public class test : MonoBehaviour { // Start is called before the first frame update void Start() { float height1 = 184.5f; float height2; height2 = height1; Debug.Log(height2); // height2 = height1 = 184.5f; // 결과값 출력 : 184.5 } // Update is called once per frame void Update() { // 현재 캐릭터를 조금씩 ..

카테고리 없음 2023.09.06