using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
직렬화 (Serialization)
데이터 구조 또는 게임오브젝트 상태를 보관하고 관리하는 기법
인스펙터 창에서 오브젝트의 직렬화된 멤버변수 값을 보여줌
이를 이용하여 소스코드의 수정 없이 유니티 에디터에서 값을 변경 가능
<데이터 직렬화>
오브젝트의 멤버변수 값을 확인하거나 변경
오브젝트의 멤버변수 참조를 드래그 앤 드랍 방식으로 연결
[Header("Value")]
C# Type
public bool boolValue;
public int intValue;
public float floatValue;
public string stringValue;
Unity Type
public Vector3 vector3;
public Vector3Int vector3Int;
public Vector2 vector2;
public Vector2Int vector2Int;
public Color color;
public Rect rect;
public LayerMask layerMask;
public AnimationCurve curve;
public Gradient gradient;
열거형
public ForceMode mode;
public enum Tyep { None, Special, Master }
public Tyep tyep;
직렬화 가능한 필드의 배열 및 List<T>
public int[] array;
public List<int> intList;
[Header("Reference")]
Object Type
public new GameObject gameObject;
public new Transform transform;
public new Rigidbody rigidbody;
public new Collider collider;
<어트리뷰트>
클래스, 속성 또는 함수 위에 명시하여 특별한 동작을 나타낼 수 있는 마커
[Header("Unity Attribute")]
[SerializeField]
private int privateValue;
[HideInInspector]
public int publicValue;
[Range(0, 100)]
public float rate;
[TextArea(3, 5)]
public string textField;
[Serializable]
public struct StructType
{
public int value1;
public string value2;
}
public StructType structField;
[Serializable]
public class ClassType
{
public int value1;
public string value2;
}
public ClassType classField;
변수 : 정보
public Rigidbody rigid;
public float junpPower;
public float movePower;
유니티 메시지 함수
유니티가 보내는 메시지에 반응하는 함수
MonoBehaviour 클래스에 메시지와 같은 이름의 함수가 반응
스크립트는 유니티 엔진이 보내는 메시지를 받아 사건 타이밍을 확인
메시지 함수에서 자신의 행동을 정의하여 기능을 구성
함수 : 기능
private void Awake()
{
Debug.Log("Awake");
}
private void Start()
{
Debug.Log("Start");
}
private void OnEnable()
{
Debug.Log("OnEnable");
}
private void OnDisable()
{
Debug.Log("OnDisable");
}
private void Update()
{
Debug.Log("Udpate");
if (Input.GetKey(KeyCode.LeftArrow))
{
rigid.AddForce(Vector3.left * movePower, ForceMode.Force);
}
if (Input.GetKey(KeyCode.RightArrow))
{
rigid.AddForce(Vector3.right * movePower, ForceMode.Force);
}
if (Input.GetKey(KeyCode.UpArrow))
{
rigid.AddForce(Vector3.forward * movePower, ForceMode.Force);
}
if (Input.GetKey(KeyCode.DownArrow))
{
rigid.AddForce(Vector3.back * movePower, ForceMode.Force);
}
if (Input.GetKeyDown(KeyCode.Space))
{
rigid.AddForce(Vector3.up * junpPower, ForceMode.Impulse);
}
}
private void LateUpdate()
{
Debug.Log("LateUpdate");
}
private void FixedUpdate()
{
Debug.Log("FixedUdpate");
}
private void OnDestroy()
{
Debug.Log("OnDestroy");
}
}