using System.Collections; using System.Collections.Generic; using UnityEngine; public class Move : MonoBehaviour { public float maxSpeed; Rigidbody2D rigid; SpriteRenderer spriteRenderer; Animator anim; void Awake() { rigid = GetComponent(); spriteRenderer = GetComponent(); anim = GetComponent(); } void update() { //stopspeed if (Input.GetButtonUp("Horizontal")) { rigid.velocity = new Vector2(rigid.velocity.normalized.x*0.5f, rigid.velocity.y); } //Direction sprite if(Input.GetButtonDown("Horizontal")) spriteRenderer.flipX = Input.GetAxisRaw("Horizontal") == -1; //animation if (Mathf.Abs(rigid.velocity.x) maxSpeed)//right max speed rigid.velocity = new Vector2(maxSpeed, rigid.velocity.y); else if(rigid.velocity.x
๋ฐฉํฅํค์ ๋ฐ๋ฅธ ํ๋ฆฝ ์ ํ์ด๋ย ย ์ ๋๋ฉ์ด์
์ ํ์ด ๋จนํต์ด๋ค์ย
//Direction sprite
if(Input.GetButtonDown("Horizontal"))
spriteRenderer.flipX = Input.GetAxisRaw("Horizontal") == -1;
//animation
if (Mathf.Abs(rigid.velocity.x)
์ด๋ถ๋ถ์ด ๋ฌธ์ ์ธ๊ฒ๊ฐ์๋ฐ ์์๋๋ถ
๊ทธ๋ฅ float xinput = Input.GetAxis("Horizontal'); ํ๊ณ xinput์ด 0๋ณด๋ค ํด๋ spriterenderer.flipX = false, ์์๋ true๋ก ํ๋ฉด ๋ ๊ฑธ - dc App
//animation ์ดํ์ ๋ฌธ๋ฒ๋ ์ด์ํด. Mathf.Abs๋ maxSpeed๋ ์๋ง๋ ๋น๊ตํ๋๊ฑฐ๊ฐ์๋ฐ ๋ถ๋ฑํธ๋ ์๊ณ ... - dc App
spriteRenderer.flipX = Input.GetAxisRaw("Horizontal") == -1; ์ด๋ถ๋ถ์ if(Input.GetAxisRaw("Horizontal") == -1) spriterenderer.flipX = true; else spriterenderer.flipX = false;๋ก ๊ณ ์น๋ฉด ๋ฐฉํฅ์ ๋ฐ๋๊ฑฐ์ผ - dc App
์ ์ด์์ฌ ์๋ผ ์ด๋ ค์ค
์ค๋ง ์ ๊ธฐ GetComponent(); ์ ๊ฒ ์ง์ง ์ ๋ ๊ฒ ๋์ด์๋๊ฑด ์๋์ง? ์๋ตํ๊ฑฐ์ง? - dc App
??? ์ ๊ฑฐ ์๋?
๋ญ ๋ฐ์์ฌ๊ฑด์ง ์จ๋์ผ์ง... rigid = GetComponent<Rigidbody2d>(); spriteRenderer = GetComponent<SpriteRenderer<(); anim = GetComponent<Animator>(); ๋ก ๊ณ ์ณ - dc App
๊ณ ์ณค์
์ด์ํ๊ฒ ์ฌ๊ธฐ๋ก ๋ถ์ฌ์ฐ๊ธฐํ ๋ <>์์ ๋ฌธ๋ฒ๋ค์ด ๋ถ์ฌ์ฐ๊ธฐ๊ฐ ์๋ฌ๋๋ด
์๋ ์ด ๊ฐ๋จํ ๋ฌธ๋ฒ๋ค์ด ์ ์๋จนํ๋๊ฑด์ง ๋ชจ๋ฅด๊ฒ ๋ค ์ ๋ํฐ์์์ ๋ฌธ์ ์๋
ํน์ ์ ํ๋ธ ๊ณจ๋๋ฉํ ๊ฐ์ข ๋ณด๊ณ ๋ง๋ฌ?
์์ค์์ค ๋งํ์ ์์ฃผ ์ฃฝ๊ฒ ์
flip.x ํ๋ ๋ฌธ๋ฒ์ ์ข์ฐ ํค ์ ๋ ฅ ๋ฐ๋ ๊ณณ์๋ค ๋ฃ์ง ๋ง๊ณ ์ข์ฐ ์ด๋ํ๋ ๊ณณ์ ๋ฃ์ด์ค ๋ด. ๋ด ์๊ฐ์ ๊ธ์ด์ด๊ฐ ๊ฒช๋ ๋ฌธ์ ๋ ์ข์ฐ ํค ์ ํ ํ ๋ ์์ชฝ ํค๋ฅผ ๋๋ฅด๋ ์๊ฐ์ด ์์ผ๋ฉด ๋ฌธ์ํฌ ๋๋ ๋ฌธ์ (ํด๋น ์ ํ๋ธ ์์ ๋ง๊ธ์์๋ ์ ๋ณด๋จ)์ธ๋ฐ ์ด๋ฌ๋ฉด ๊ทธ๋ฅ ์์ผ๋ก ๊ฐ๋ ๋ฐฉํฅ ์ชฝ์ผ๋ก ๋ฐ์ ๋จ
์ง๊ธ ๋ฐ์ด๋ผ ์ด๋ ๊ฒ๋ฐ์ ์ค๋ช ์ ๋ชปํด์ใ ใ ... ๋ฌธ์ ํด๊ฒฐ ์๋๋ฉด ๋ค์ ๋ง๊ธ์ข ์ฃผ์ ์ฝ๋ ๋ณต์ฌํด์ ๋ฌ์์ค๊ฒ
์๋ง ๋ณธ๋ฌธ์๋ ์๋ ์ฝ๋์์ ๋ฐ์ํ ์ฌํญ์ผํ ๋ฐ, ์์ ์ฝ๋ ๊ทธ๋๋ก ๋ฐ๋ผํ์ผ๋ฉด ๋ด๊ฐ ๋งํ๋๋ก ๊ณ ์ณค์ ๋ ์ ๋๋ก ์๋๋ ๊ฒ์ ๋ง๋ค ๊ทธ ์ข์ฐ ํค ์ ๋ ฅ ๋ฐ๋ ์ฝ๋๋ ์ง์์ฃผ๋๊ฒ ์ข์
์ง๊ธ ๊ฒ๋ ์ ๊ธฐํจ... ํ๋ก์ ํธ ๋ค์ ์์ฑํด์ ์ฒ์๋ถํฐ ์ฐจ๊ทผ ์ฐจ๊ทผ ์ ์์๊ฑฐ ํ๋ ํ๋์ฉ ๋ถ์ฌ๋ฃ๊ธฐ ํ๋๋ฐ
ํ๋ฆฝ์ด ์๋จ ... ์ฝ๋๋ ๋๊ฐ์๋ฐ ๋ค๋ง ์ด์ํ๊ฒ
๋ญ๊ฐ ์๋ก ์ถฉ๋์ด ์ผ์ด๋๋ค..์๊ฑฐ ๋ฃ์ผ๋ฉด ์ ๊ฒ ์๋๊ณ ์๋ฌดํผ ํ๋ฆฝ์ ํด๊ฒฐํจ ใณใณ
์ใ ใ ๊ฐ์ ํตํผ ์ฐ๊ธดํ๋ฐ ๋งจ ์ ๋์ด๋ ๊ฐ์์ฌ๋ ์๋ใ ใ ใ ์ํผ ํด๊ฒฐ๋์๋ค๋ ๋คํ์