no image
[고1 게임엔진] 09 - (3)
using System.Collections; using System.Collections.Generic; using UnityEngine; public class Forever_Chase : MonoBehaviour { // (유령이) 플레이어를 계속 추적한다(Chase) public float speed = 3; // 유령의 이동속도 public string targetObjectName; // 목표 오브젝트의 이름 저장 // 리지드바디컴포넌트형 변수선언(클래스명 변수명 = new 클래스명()) Rigidbody2D rb; // 게임오브젝트형 변수선언 GameObject targetObject; void Start() { rb = GetComponent(); rb.gravityScale = 0; rb..
2023.09.13
no image
[고1 게임엔진] 09 - (2)
using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerController : MonoBehaviour { // 좌우이동 && 점프(velocity만 사용) // 리지드바디2D형 변수선언 Rigidbody2D rb; [HideInInspector] public float speed = 5; // 좌우이동시 이동 속도 public float jumpPower = 8; // 점프력 float axisH; // 좌우이동 여부 // public 처럼 에디터에서 편집 가능, 하지만 외부스크립트에서는 접근불가(private) [SerializeField] Transform tr; // 트랜스폼 컴..
2023.09.11
no image
[고1 게임엔진] 09 - (1)
Move_Flip using System.Collections; using System.Collections.Generic; using UnityEngine; public class Move_Flip : MonoBehaviour { // 좌우반전 // 전역변수 선언 Rigidbody2D rb; public float speed = 5; // 좌우이동시 이동 속도 public float power = 5; // 점프력 float vx = 0; // 좌우방향키 누르고있는지 여부(오른쪽 +1, 왼쪽 -1) bool isJumping = false; // 점프여부 bool groundFlag = false; // 발이 무언가에 닿아있는지 여부 void Start() // 유니티 실행하자마자 처음 한번만 실행. ..
2023.09.04
no image
[고1 게임엔진] 08 - (1)
OnKeyPress_Move using System.Collections; using System.Collections.Generic; using UnityEngine; public class OnPressKey_Move : MonoBehaviour { // 전역변수 float vx = 0; // x축으로 이동하는 이동량 float vy = 0; // y축으로 이동하는 이동량 bool flag = false; // 반전여부(true/false) void Update() // 계속 시행한다(비정기적인 간격으로) { vx = 0; vy = 0; if (Input.GetKey("right")) // 키보드 키 눌렸다면, Input.Getkey(KeyCode.RightArrow) { vx = 5; flag = ..
2023.08.30
no image
[고1 게임엔진] 08 - (3)
Move_Car using System.Collections; using System.Collections.Generic; using UnityEngine; public class Move_Car : MonoBehaviour { Rigidbody2D rb; // 리지드바디 2D형 변수 선언 (객체) void Start() { // 리지드바디 2D 컴포넌트 가져오기 rb = GetComponent(); // 중력을 0으로 (무중력) //rb.gravityScale = 0; // 충돌 시 회전시키지 않기 rb.constraints = RigidbodyConstraints2D.FreezeRotation; } void Update() { if (Input.GetButton("Jump")) { //rb.veloc..
2023.08.30
no image
[고1 게임엔진] 08 - (2)
Move_Velocity using System.Collections; using System.Collections.Generic; using UnityEngine; public class Move_Velocity : MonoBehaviour { int count = 0; // 초(횟수) // 리지드바디2D 변수(객체)선언-전역변수 Rigidbody2D rb; void Start() { // 리지드바디2D 컴포넌트 가져오기 rb = GetComponent(); // 중력을 0으로하고, 충돌시 회전하지않도록 설정 rb.gravityScale = 0; rb.constraints = RigidbodyConstraints2D.FreezeRotation; } void Update() // 계속 호출(실행)된다 -..
2023.08.28