no image
[고1 게임엔진] 12 - (1)
OnKeyPress_Move using System.Collections; using System.Collections.Generic; using UnityEngine; public class OnKeyPress_Move : MonoBehaviour { public float speed = 2; // 속도:Inspector에 지정 float vx = 0; float vy = 0; void Update() { // 계속 시행한다 vx = 0; vy = 0; if (Input.GetKey("right"))// 만약 오른쪽 키가 눌리면 { vx = speed; // 오른쪽으로 나아가는 이동량을 넣는다 } if (Input.GetKey("left"))// 만약 왼쪽 키가 눌리면 { vx = -speed; // ..
2023.12.27
no image
[고1 게임엔진] 11 - (2)
보낼 파일 public class GameCounter : MonoBehaviour { // 1. 카운터 본체를 만든다. public static int count; // 공유하는 카운터의 값 public int startCount = 0; // 카운터 초깃값 private void Start() { count = startCount; // 카운터값 리셋 } } ------------------------------------------------------- using UnityEngine.UI; // UI 사용 public class Forever_ShowCount : MonoBehaviour { // 2. 계속 카운터 값을 표시한다. void Update() { GetComponent().text ..
2023.11.20
no image
[고1 게임엔진] 11 - (1)
using System.Collections; using System.Collections.Generic; using UnityEngine; public class OnUpKeyPress_Throw : MonoBehaviour { // 플레이어 이동, 반전관련 변수선언 public float speed = 5; float vx; // x축 이동량 bool leftFlag = false; // 좌우반전 bool upFlag = false; // 위쪽 방향키 눌렸는지 여부 //프리팹 만들기------------------------------------ public GameObject sushi; // 공장에 넘겨줄 원본(프리팹) GameObject newSushi; // 공장에 찍어낸 새로운 아이템(프리팹..
2023.11.13
no image
[고1 게임엔진] 10 - (3)
using System.Collections; using System.Collections.Generic; using UnityEngine; public class Sometimes_RandomPrefab : MonoBehaviour { public GameObject newPrefab; // 만드는 프리팹 :Inspector에 지정한다 public float intervalSec = 1; // 작성 간격(초):Inspector로에 지정한다 void Start() { // 처음에 시행한다 // 지정 초 수마다 CreatePrefab를 반복 실행하는 예약 InvokeRepeating("CreatePrefab", intervalSec, intervalSec); } void CreatePrefab() { //..
2023.10.18
no image
[고1 게임엔진] 10 - (2)
using System.Collections; using System.Collections.Generic; using UnityEngine; public class MouseDown_CreatePrefabs : MonoBehaviour { // 마우스 클릭하면 그 자리에 프리팹 생성 // 마우스 클릭한 위치보다 조금 앞쪽에 프리팹 나타나게 public GameObject newPrefab; // 프리팹(게임오브젝트) 저장 - ghost Vector3 pos; void Start() { } void Update() { if (Input.GetMouseButtonDown(0)) { // 마우스 클릭한 위치를 카메라세상안에서의 위치로 변환해서 pos = Camera.main.ScreenToWorldPoint(..
2023.10.16
no image
[고1 게임엔진] 10 - (1)
using System.Collections; using System.Collections.Generic; using UnityEngine; public class MouseDown_Hide : MonoBehaviour { // 마우스 클릭했을 때 오브젝트가 사라진다. private void OnMouseDown() { gameObject.SetActive(false); } } using System.Collections; using System.Collections.Generic; using UnityEngine; public class MouseDown_Rotate : MonoBehaviour { float rotateAngle = 0; // 회전각도 private void OnMouseDown() ..
2023.10.11
no image
[고1 게임엔진] 09 - (6)
using System.Collections; using System.Collections.Generic; using UnityEngine; public class ChangeAnim : MonoBehaviour { public string upAnime; // 위쪽방향 애니메이션 클립이 저장되는 변수 public string downAnime; public string leftAnime; public string rightAnime; string nowMode; // 방향키눌렀을 때 그 방향의 애니메이션클립을 저장해두는 변수 Animator anim; // 애니메이터 컴포넌트형 변수선언 void Start() { anim = GetComponent(); nowMode = downAnime; } void..
2023.09.25
no image
[고1 게임엔진] 09 - (5)
using System.Collections; using System.Collections.Generic; using UnityEngine; public class Move : MonoBehaviour { // Time.deltaTime : Update() 메서드가 한번 호출되고 다시 호출되기까지 걸린시간을 의미 public float speed = 5; float h; // 좌우방향키 입력값 float v; // 상하방향키 입력값 Vector2 dir; void Start() { } // 고성능pc - Time.deltaTime 값이 매우 작은 값이 된다 // 저성능pc - Time.deltaTime 값이 매우 커지게 된다 // Time.deltaTime을 이용해서 성능차이가 있는 기기일지라도 같은 시..
2023.09.20
no image
[고1 게임엔진] 09 - (4)
using System.Collections; using System.Collections.Generic; using UnityEngine; public class Forever_Chase : MonoBehaviour { // 유령이 플레이어을 계속 쫓아다닌다. // 목표오브젝트(타겟-boy) Rigidbody2D rb; GameObject targetObject; // 타겟오브젝트를 찾기위한 변수선언 public float speed = 5; // 유령의 이동속도 public string targetObjectName; // 목표오브젝트에 이름 저장 public string showObjectName; // 표시할오브젝트 이름 저장(햄버거) GameObject showObject; // 표시할 오브젝트..
2023.09.18