게임 월드 속 사물 = 오브젝트 = 객체
객체지향 프로그래밍은 독립적인 여러 개체가 서로 상호작용하는 객체가 모여 거대한 프로그램을 만드는 방식, 즉 사람이 세상을 보는 방식을 코드화. → 클래스의 동작 방식
휴대폰 = 각종 센서와 수많은 부품의 집합 → 휴대폰이라는 하나의 객체로 우리는 인식
동물 오브젝트가 모여있는 동물원 만들기
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Animal : MonoBehaviour
{
public string name;
public string sound;
public void Playsound()
{
Debug.Log(nameof + " " + sound);
}
Animal 클래스를 기반으로 Animal 오프젝트를 만드는 Zoo스크립트 작성
public class Zoo : MonoBehaviour{
void Start(){
Animal tom = new Animal();
[tom.name](<http://tom.name/>) = "톰";
tom.sound = "냐엉";
tom.Playsound();
}
}