55,000원
다른 수강생들이 자주 물어보는 질문이 궁금하신가요?
- 미해결유니티와 C#으로 배우는 카타나제로스타일 게임만들기 (기본편)
마우스 방향으로 공격을 하고 싶습니다.
using System.Collections;using System.Collections.Generic;using UnityEngine;public class VPlayer : MonoBehaviour{ #region 변수 모음 public float speed; public float power; public Vector3 direction; Animator pAnimator; Rigidbody2D pRig2D; SpriteRenderer sp; GrapplingHook grappling; // GrapplingHook C# 코드 불러오기 #endregion #region 점프 변수 모음 [Header("Jump System")] [SerializeField] float jumpUp; [SerializeField] float fallMultiplier; [SerializeField] float jumpTime; [SerializeField] float jumpMuitiplier; Vector2 vecGravity; bool isJumping; float JumpCounter; #endregion #region 벽 점프 변수 모음 [Header("Wall Jump System")] public Transform wallChk; public float wallchkDistance; public LayerMask wLayer; bool isWall; public float slidingSpeed; public float wallJumpPower; public bool isWallJump; float isRight = 1; #endregion #region 공격 관련 변수 [Header("Attack System")] public GameObject Vslash; // 공격 모션 #region 마우스 관련 변수 모음 Vector2 MousePos; Vector3 dir; float angle; Vector3 dirNo; #endregion #endregion #region 초기화 void Start() { pAnimator = GetComponent<Animator>(); pRig2D = GetComponent<Rigidbody2D>(); direction = Vector2.zero; sp = GetComponent<SpriteRenderer>(); grappling = GetComponent<GrapplingHook>(); vecGravity = new Vector2(0, -Physics2D.gravity.y); } #endregion void Update() { if (!isWallJump) { KeyInput(); Move(); mousePos(); } #region 점프 키 누름 if (Input.GetKeyDown(KeyCode.W)) { if (pAnimator.GetBool("Jump") == false) { Jump(); isJumping = true; JumpCounter = 0; pAnimator.SetBool("Jump", true); //JumpDust(); } } #endregion #region 점프 후 떨어질 때 가속 if (pRig2D.velocity.y < 0) { pRig2D.velocity -= vecGravity fallMultiplier Time.deltaTime; } #endregion #region 점프 키를 꾹 눌렀을 시 더 높이 점프 if (pRig2D.velocity.y > 0 && isJumping) { JumpCounter += Time.deltaTime; if (JumpCounter > jumpTime) isJumping = false; pRig2D.velocity += vecGravity jumpMuitiplier Time.deltaTime; } if (Input.GetKeyUp(KeyCode.W)) { isJumping = false; } #endregion #region 벽인지 체크 isWall = Physics2D.Raycast(wallChk.position, Vector2.right * isRight, wallchkDistance, wLayer); pAnimator.SetBool("Wall", isWall); #endregion #region 벽타기 if (isWall) { isWallJump = false; pRig2D.velocity = new Vector2(pRig2D.velocity.x, pRig2D.velocity.y * slidingSpeed); #region 벽을 잡고 있는 상태에서 점프 if (Input.GetKeyDown(KeyCode.W)) { isWallJump = true; //벽점프 먼지 //GameObject go = Instantiate(walldust, transform.position + new Vector3(0.6f * isRight, -0.32f, 0), Quaternion.identity); //go.GetComponent<SpriteRenderer>().flipX = sp.flipX; Invoke("FreezeX", 0.3f); pRig2D.velocity = new Vector2(-isRight wallJumpPower, 0.9f wallJumpPower); sp.flipX = sp.flipX == false ? true : false; isRight = -isRight; } #endregion } #endregion } private void FixedUpdate() { #region 바닥 감지 레이저 Debug.DrawRay(pRig2D.position, Vector3.down, new Color(0, 1, 0)); RaycastHit2D rayHit = Physics2D.Raycast(pRig2D.position, Vector3.down, 0.8f, LayerMask.GetMask("Ground")); #endregion #region Ground를 감지할 때 if (pRig2D.velocity.y < 0) { if (rayHit.collider != null) { if (rayHit.distance < 0.6f) { pAnimator.SetBool("Jump", false); } } #region 6-2. 떨어질 때의 감지 방식 else { if (!isWall) { //그냥 떨어지는 중 fall pAnimator.SetBool("Jump", true); } else { //벽타기 pAnimator.SetBool("Wall", true); } } #endregion } #endregion } #region 키 입력 void KeyInput() { direction.x = Input.GetAxisRaw("Horizontal"); #region 왼쪽 if (direction.x < 0) { //left sp.flipX = true; //점프벽잡기 방향 isRight = -1; pAnimator.SetBool("Run", true); } #endregion #region 오른쪽 else if (direction.x > 0) { //right sp.flipX = false; //점프벽잡기 방향 isRight = 1; pAnimator.SetBool("Run", true); } #endregion #region Idle 상태 else if (direction.x == 0) { pAnimator.SetBool("Run", false); } #endregion #region 공격 버튼 if (Input.GetMouseButtonDown(0)) { pAnimator.SetTrigger("Attack"); //Instantiate(hit_lazer, transform.position, Quaternion.identity); } #endregion } #endregion #region 이동 void Move() { if (direction.x != 0) { if (grappling.isAttach) { pRig2D.AddForce(new Vector2(direction.x * speed, 0)); //로프 이동 } else pRig2D.velocity = new Vector2(direction.x * speed, pRig2D.velocity.y); //보통 이동 } } #endregion #region 점프 public void Jump() { pRig2D.velocity = new Vector2(pRig2D.velocity.x, jumpUp); } #endregion #region 마우스 방향 public void mousePos() { Transform tr = GetComponent<Transform>(); MousePos = Input.mousePosition; MousePos = Camera.main.ScreenToWorldPoint(MousePos); Vector3 Pos = new Vector3(MousePos.x, MousePos.y, 0); dir = Pos - tr.position; // 바라보는 각도 구하기 angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg; } #endregion #region 공격 이펙트 public void AttSlash() { pRig2D.AddForce(dir.normalized * power, ForceMode2D.Impulse); GameObject go = Instantiate(Vslash, transform.position, Quaternion.identity); if (dir.x <= 0) { sp.flipX = true; } else { sp.flipX = false; } } #endregion void FreezeX() { isWallJump = false; }} 마우스 방향 값을 이용해 좌클릭을 할 때 마우스 방향으로 공격을 하는 코드를 짜고 있는 데, 이동을 velocity로 해서 그런지 idle 상태 run 상태에서 좌클릭을 누르면 공격 모션만 마우스 방향으로만 가고 플레이어는 마우스 방향으로 앞으로 대쉬하지 않습니다. 이때는 어떻게 처리해야 하는 지 알려주시면 감사하겠습니다. 코루틴도 써봤지만 답이 안나와서 올립니다.
- 미해결유니티와 C#으로 배우는 카타나제로스타일 게임만들기 (기본편)
스크립트 오류 관련
public class Player : MonoBehaviour { public float speed = 5; public float jumpUp = 1; public Vector3 direction; Animator pAnimator; Rigidbody2D pRig2D; SpriteRenderer sp; // Start is called before the first frame update void Start() { pAnimator = GetComponent<Animator>(); pRig2D = GetComponent<Rididbody2D>(); direction = Vector2.zero; sp = GetComponenet<SpriteRenderer>(); } void Keyinput() { direction.x = Input.GetAxisRaw("Horizontal"); // left -1 right +1 if (direction.x < 0) { // left sp.flipX = true; } else if (direction.x > 0) { // right sp.flipX = false; } else if (direction.x == 0) { } } // Update is called once per frame void Update() { Keyinput(); Move(); } public void Move() { transform.position += direction * speed * Time.deltaTime; } } 스크립트에 문제 있는 부분 확인 부탁드립니다
- 미해결유니티와 C#으로 배우는 카타나제로스타일 게임만들기 (기본편)
강좌가 마음에 드는데 심화과정 만드실 계획 있으신가요?
궁금합니다. 심화과정 만들어지면 그것도 결제 해서 듣고 싶네요.
- 미해결유니티와 C#으로 배우는 카타나제로스타일 게임만들기 (기본편)
계단에서 착지시 문제점!
안녕하세요 강사님! 수업 잘보고있습니다 다른게 아니라 만약에 게단에서 점프하고 Line Step(계단) 위에 착륙하면 점프애니매이션과 함께 미끄러지거든요! 지금gravityScale으로 제어해서 저런 오류가 발생한거는 알겠는데 다른 수정방안이 있을까요?
- 미해결유니티와 C#으로 배우는 카타나제로스타일 게임만들기 (기본편)
4번째 강의 질문
플레이어 스크립트를 시작하실때 Vector3 를 direction으로 받으시고 밑에 Start에서는 왜 Vector2.zero; 를 주신건가요?
- 해결됨유니티와 C#으로 배우는 카타나제로스타일 게임만들기 (기본편)
강의 질문드립니다.
jumpdust_wall 이펙트 부분을 진행중인데 이전 강의까지 jumpdust를 만든적이 없는데 강의에서 계속 jumpdust에 대해서 언급합니다. 어떻게 된건가요? 먼지효과내기2에서 벽설치로 넘어갈때 갑자기 jumpdust가 생깁니다. + 임시 해결 + 일단 jumpdust_wall 이미지를 90도 회전시켜서 jumpdust 이미지로 사용했고 jumpdust 스크립트는 landdust와 동일하게 작성해서 jumpdust 프리팹에 추가시켰습니다. player 스크립트에 추가된 내용은 강의 내용을 일시정지 해가면서 수정했습니다
- 미해결유니티와 C#으로 배우는 카타나제로스타일 게임만들기 (기본편)
엣지콜라이더설치후 폴리싱 관련된 부분 질문드립니다.
계단부분을 처리하기 위해 엣지콜라이더를 설치 후 플레이어가 엣지콜라이더와 충돌시 중력값을 0으로 만들어 오르막길을 문제 없이 올라가게 하는 부분은 이해가 됐습니다만. 중력값이 0임에도 불구하고 정지상태에서 계속 아래로 캐릭터가 미끄러지듯 내려가는 부분을 확인할 수 있었습니다. 이런 2d 픽셀류 게임에서 일일이 박스콜라이더를 계단모양으로 일일이 배치하진 않을 것 같은데, 엇지 콜라이더 경사면에서 미끄러지지 않기 위해서 추가적으로 어떤 코드를 넣어야 할까요?
- 미해결유니티와 C#으로 배우는 카타나제로스타일 게임만들기 (기본편)
강의 순서가 이상해 질문 올립니다~
안녕하세요. 강사님 수업을 열심히 듣고있는 학생입니다. 올려주신 수업순서 중 공격이펙트 2강의에서 공격이펙트 마무리 강의영상으로 넘어가며 그래픽을 리뉴얼 하시기이전의 원본카타나 제로영상이 들어가있습니다. 그래도 이어지는 강의 내용이겠거니하고 보았지만 이 강의 내용은 공격이펙트 마무리영상이 아닌 걸 알수있습니다. 그렇게 공격이펙트 관련하여 마무리 되지 않은 체 강의가 끝나고 그 다음 강의는 이전강의와 전혀 연관이 없는 그림자이펙트강의가 들어갑니다. 이전수업에서 공격이펙트가 플립이 안된버젼으로 스크립트가 마무리지어져 캐릭터 좌우 방향에 상관없이 한쪽방향으로만 공격이펙트가 나갑니다만, 다음수업들은 모두 캐릭터 방향에 따라 올바르게 공격이펙트가 나가는 것을 볼 수 있습니다.(물론 수업을 열심히 들었으면 강의내용이 없어도 해당 스크립트를 구현하는데 문제가 없습니다만...제가 구현한 부분이 강사님과 같게 구현되었는지 궁금하네요.)<- 쓰고 나서 다음강의 듣다보니 영상 지나가는부분 잠깐 정지눌러 구현하신 스크립트 확인완료했습니다. 아마 영상을 올리실 때 최근다시 찍으신 강의 대신 이전강의 영상이 섞여 문제가 발생한 것 같은데 확인되시는대로 영상교체 부탁드리겠습니다^^; 쓰다지우고 쓰다 지우고 해서 말이 뒤죽박죽입니다만 양해부탁드립나다.^^;