본문 바로가기

Unity/C# 문법12

[유니티] 상속 문법(부모/자식 class) 1. 상속 문법 사용(전) using System.Collections; using System.Collections.Generic; using UnityEngine; //속성 메소드 중복 => 수정해야할때 문제가 될 수 있음 //=> 상속으로 해결! public class HumanBefore { public string name; //중복 public int hp; //중복 public int damage; //중복 public int level; public int gravity; public string talkMessage; public void Talk() { Debug.Log(name + "대화내용 : " + talkMessage); } //중복 public void Move() { Debu.. 2021. 4. 27.
[유니티] 데이터 은닉(캡슐화)+생성자 1. 데이터 은닉 using System.Collections; using System.Collections.Generic; using UnityEngine; public class ItemInfo { private string name; private int price; private int damage; private int type; public void SetItemInfo(string name, int damage, int price, int type) { this.name = name; this.damage = damage; this.price = price; this.type = type; } public void PrintInfo() { Debug.Log("아이템 이름 >>>" + name.. 2021. 4. 27.
[유니티] 분기문(반복문 종료하기 Break, Continue) using System.Collections; using System.Collections.Generic; using UnityEngine; // if 문에서 명령이 한개이면 {} 생략가능 조건 여러개일때 {} 추가 public class BreakContineEx : MonoBehaviour { // Start is called before the first frame update void Start() { //for (int i=0; i 2021. 4. 27.
[유니티] 무조건 외워야 할 문법!! 1. text(string)값을 정수로 변환 itemCountText의 text(string) 값을 정수로 변환함 string -> int : int.Parse("문자열"); int count = int.Parse(itemCountText.text); 2. 정수를 문자로 변환 int -> string : 정수형변수.ToString(); itemCountText.text = count.ToString(); 3. 카운트값 1 증가 count = count + 1; count += 1; count++; 4. 프리팹을 게임오브젝트로 생성하는 메소드 : Instantiate() -> Object.Instantiate(프리팹참조변수, 생성위치, 생성시회전); Instantiate(itemPrefab, tempPos.. 2021. 4. 25.