2024/03/18 3

[C#] Action Invoke로 인자 전달하기

public class Class1 : MonoBehaviour { Action action; private void Trigger() { action.Invoke(); } } public class Class2 : MonoBehaviour { private void Start() { action += {Class1 Component}.ActionFunc } public void ActionFunc() { Debug.Log("action"); } } 기본적으로 Action을 사용해서 다른 클래스의 특정 함수를 동작시키기 위해서는 1. Action 변수 생성 2. 다른 클래스에서 해당 Action에 함수를 추가 3. Action을 Invoke 하면 다른 클래스의 해당 함수가 실행 하는 식으로 동작한다 그런..

[Error] get_persistentDataPath is not allowed to be called from a MonoBehaviour constructor

GameManagerEx 스크립트 파일에서 로컬 저장 기능 구현을 위해 path 변수를 선언하는 과정에서 에러 메시지가 발생하였다 public string _path = Application.persistentDataPath + "/SaveData.json"; UnityException: get_persistentDataPath is not allowed to be called from a MonoBehaviour constructor (or instance field initializer), call it in Awake or Start instead. Called from MonoBehaviour 'Managers' on game object '@Managers'. See "Script Seriali..

[Unity] Rect Transform Animation Position 변경하기

Rect Transform을 갖고 있는 텍스트 오브젝트에 애니메이션을 붙이려고 했는데, Position Property를 선택했더니 Z 포지션밖에 변경할 수가 없었다 Position 대신 Anchored Position을 사용해야 x와 y의 위치를 조정할 수 있다 Anchored가 붙어 있어 Anchors를 조정하는 프로퍼티라고 생각했는데, Anchors 프로퍼티는 따로 있었다 출처: https://forum.unity.com/threads/i-can-only-change-rect-transforms-z-position.328178/