본문 바로가기
반응형

Unity12

void Start() 컴포넌트 초기화 부분 스크립트가 붙은 해당 오브젝트가 처음으로 생성 되는 그 순간 and 오브젝트 활성화 상태일 때 최초로 1 회 실행된다. 유니티가 Start 메세지를 브로드캐스팅 하여 뿌려 온 컴포넌트들을 각자 구현된 Start 내용대로 초기화 시킨다. 유니티는 게임 시작할때 Start 메세지를 뿌린다. Awake() 후 + Update() 전에 1회 동작하는 이벤트 함수다. 오브젝트가 최초 생성될 때 실행 순서 Awake() 👉 OnEnable() 👉 Start() Awake 와의 차이점 둘 다 오브젝트가 생성될 때(스크립트가 최초로 실행될 때) 최초 1회 실행된다는 점에서 같다. 그러나 Awake() 코루틴 실행이 안된다. Start()보다 먼저 실행된다. 스크립트(컴포넌트)가 비활성화인 상태에서.. 2023. 3. 14.
오브젝트 색상변경 스크립트 using UnityEngine; using System.Collections; public class ExampleBehaviourScript : MonoBehaviour { void Update() { if (Input.GetKeyDown(KeyCode.R)) { GetComponent ().material.color = Color.red; } if (Input.GetKeyDown(KeyCode.G)) { GetComponent().material.color = Color.green; } if (Input.GetKeyDown(KeyCode.B)) { GetComponent().material.color = Color.blue; } } } 2023. 3. 14.
케릭터이동 코드 Move.cs using System.Collections; using System.Collections.Generic; using UnityEngine; public class Move : MonoBehaviour { public float movementSpeed = 3.0f; Vector2 movement = new Vector2(); Rigidbody2D rigid; Animator animator; // Start is called before the first frame update void Start() { animator = GetComponent(); rigid = GetComponent(); } // Update is called once per frame void Update() { .. 2023. 3. 8.
객체 자동 이동 public class Enemy : MonoBehaviour { public Transform target; public Vector3 direction; public float velocity; public float default_velocity; public float accelaration; public Vector3 default_direction; void Start () { // 자동으로 움직일 방향 벡터 default_direction.x = Random.Range (-1.0f, 1.0f); default_direction.y = Random.Range (-1.0f, 1.0f); // 가속도 지정 (추후 힘과 질량, 거리 등 계산해서 수정할 것) accelaration = 0.1f; de.. 2023. 3. 6.
ObjectItem.cs public class ObjectItem : MonoBehaviour, IObjectItem { [Header("아이템")] public Item item; [Header("아이템 이미지")] public SpriteRenderer itemImage; void Start() { itemImage.sprite = item.itemImage; } public Item ClickItem() { return this.item; } } 자료출처 : https://geojun.tistory.com/62 2023. 3. 6.
인벤토리 소스 item.cs using UnityEngine; [CreateAssetMenu] public class Item : ScriptableObject { public string itemName; public Sprite itemImage; } Slot.cs using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class Slot : MonoBehaviour { [SerializeField] Image image; // Image Componet 담는곳 private Item _item; public Item item { get { return _item; } //슬롯의.. 2023. 3. 6.
반응형