using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
ย ย GameObjectManager gameobjectmanager;
ย ย Rigidbody2D rigid2d;
ย ย Animator animator;
ย ย //ํ๋ ์ด์ด ์บ๋ฆญํฐ ์ด๋์๋
ย ย private float P_movespeed = 3.0f;
ย ย //ํ๋ ์ด์ด ์บ๋ฆญํฐ ์ ํ๋์ด
ย ย private float P_JumpForce = 300.0f;
ย ย //ํ๋ ์ด์ด ์ด๋์๋ ์ ํ
ย ย private float P_maxMoveSpeed = 3.0f;
ย ย //๊ฐํ์์น์ ๋ฐ๋ฅธ ์ด๋, ์ ํ์๋ ์ฆ๊ฐ๋
ย ย public float P_IncreaseSpeed = 0.2f;
ย ย public float P_IncreaseJump = 100.0f;
ย ย void Start()
ย ย {
ย ย ย ย this.gameobjectmanager = GameObject.Find("GameObjectManager").GetComponent<GameObjectManager>();
ย ย ย ย this.rigid2d = GetComponent<Rigidbody2D>();
ย ย ย ย this.animator = GetComponent<Animator>();
ย ย }
ย ย void Update()
ย ย {
ย ย ย ย this.P_movespeed += this.P_IncreaseSpeed * this.gameobjectmanager.m_PlayerSpeedUp;
ย ย ย ย this.P_JumpForce += this.P_IncreaseJump * this.gameobjectmanager.m_PlayerJumpUp;
ย ย ย ย //์คํ์ด์ค ๋ฐ๋ฅผ ๋๋ฅผ ์ ์ ํ
ย ย ย ย if (Input.GetKeyDown(KeyCode.Space)&&this.rigid2d.velocity.y == 0)
ย ย ย ย {
ย ย ย ย ย ย this.rigid2d.AddForce(transform.up * this.P_JumpForce);
ย ย ย ย }
ย ย ย ย if (this.rigid2d.velocity.y != 0)
ย ย ย ย {
ย ย ย ย ย ย this.animator.SetTrigger("JumpTrigger");
ย ย ย ย }
ย ย ย ย //์ข์ฐ ์ด๋
ย ย ย ย int k = 0;
ย ย ย ย if(Input.GetKey(KeyCode.RightArrow))
ย ย ย ย {
ย ย ย ย ย ย k = 1;
ย ย ย ย }
ย ย ย ย if(Input.GetKey(KeyCode.LeftArrow))
ย ย ย ย {
ย ย ย ย ย ย k = -1;
ย ย ย ย }
ย ย ย ย //ํ๋ ์ด์ด ์ด๋์๋
ย ย ย ย float speedx = Mathf.Abs(this.rigid2d.velocity.x);
ย ย ย ย //์ด๋
ย ย ย ย if (speedxย < this.P_maxMoveSpeed)
ย ย ย ย {
ย ย ย ย ย ย this.rigid2d.AddForce(transform.right * k * P_movespeed);
ย ย ย ย }
ย ย ย ย speedx *= k;
ย ย ย ย //ํ๋ ์ด์ด๊ฐ ๋๊ธฐ ์ค์ธ์ง ํ์ธ, ์ด๋ ๋ชจ์ ์ด ์์ ๊ฒฝ์ฐ ๋๊ธฐ ๋ชจ์ ์ถ๋ ฅ
ย ย ย ย if (speedx == 0&&this.rigid2d.velocity.y == 0)
ย ย ย ย {
ย ย ย ย ย ย this.animator.SetTrigger("IdleTrigger");
ย ย ย ย }
ย ย ย ย //ํ๋ ์ด์ด๋ฅผ ์์ง์ด๊ณ ๊ณต์ค์ ์์ง ์์ ๋ ๊ฑท๋ ์ ๋๋ฉ์ด์ ์ด ์ถ๋ ฅ
ย ย ย ย if (speedx != 0&&this.rigid2d.velocity.y == 0)
ย ย ย ย {
ย ย ย ย ย ย this.animator.SetTrigger("WalkTrigger");
ย ย ย ย }
ย ย
ย ย ย ย //ํ๋ ์ด์ด ํ์
ย ย ย ย if (k !=0)
ย ย ย ย {
ย ย ย ย ย ย transform.localScale = new Vector3(2*k, 2, 2);
ย ย ย ย }
ย ย ย
ย ย }
}
๋งต ์ ์ ์์ ํ๊ณ ์๊ณ ํ์ผ๋งต ์ฝ๋ผ์ด๋ ๋ฃ์๋๋ ์ค๊ฐ์ ๋๊ธฐ๋ ๋ถ๋ถ(์๋ง ํฝ์ ๋ฌธ์ ์ธ๋ฏ)์ด ์์ด์ y๊ฐ์ด ๋ฐ๋๋๊น ๊ทธ๋ฌ๋ ค๋ ํ๋๋ฐ
์ปดํฌ์ง ๋ฃ์ผ๋๊น ๊ฑท๋ ์ ๋๋ฉ์ด์ ์ด ์ ๋์ค๊ณ ์์๋ก ์ ํํด๋ฒ๋ฆฌ๋ ์ ๋๋ฉ์ด์ ์ด ๋์๋ฒ๋ฆฌ๋๋ฐ velocity y๊ฐ์ด ๋ชป๋ฐ๋๊ฒ๋ ๋ชปํ ๊น ์ด๊ฑฐ?
์ฝ๋๊ฐ ์กฐ๊ธ ์ด์ํ๊ฒ ๊ฐ์. y์ถ ์๋๊ฐ 0์ด๋ฉด ๋ฌด์กฐ๊ฑด ์ง์์ด๋ผ๊ณ ํ๋จํ๊ณ ์๋๊ฒ ๊ฐ์๋ฐ ํ๋ฆฐ๊ฒ ๊ฐ์. ์๋ฅผ ๋ค๋ฉด ์ ํํด์ ์๋ก ์ฌ๋ผ๊ฐ์๋
์ต๊ณ ๋์ด์ ๋๋ฌํ๋ฉด y์ถ ์๋๋ 0์ด ๋์ง ์์๊น?
ใ ใ ์ผ๋จ ์ฐธ๊ณ ํด๋ณผ๊ฒ ใณใณ
๋ํ ์ ํ ์ ๋๋ฉ์ด์ ํธ๋ฆฌ๊ฑฐ๋ฅผ y์ถ ์๋๊ฐ 0์ด ์๋๋๋ก ํ๋๋ฐ ๊ทธ๋ฌ๋ฉด ์ ๋ฒฝ์์ ๋จ์ด์ ธ๋ ์ ํํ๋ ์ ๋๋ฉ์ด์ ์ ์ฌ์ํ๋๊ฑฐ ์๋?
์ ๋ฒฝ์์๋ ์ ํ ์ ๋๋ฉ์ด์ ๋์ค๊ฒ ์ค์ ํ ๋ผํ์ ๋ฐ๊ตด๋ฐ๊ตด๊ฑฐ๋ฆฌ๋ ๊ทธ๋ฐ ๋ชจ์ ์ด ์์ด์ ์ผ๋ถ๋ฌ ๊ทผ๋ฐ ์ง๊ธ ๋ฌธ์ ๋ ๊ทธ๋ฅ ๊ฑธ์ด๋ค๋๋๋ ์ ํ๋ชจ์ ์ด ๋์ด;
๊ทธ๋ฅ ํด๋ฆฌ๊ณค ํ์ ์ผ๋ก ํ๋๊น ๋ฐ๋ก๊ณ ์ณ์ก๋ค... ๊ทธ๋๋ ์๋ ค์ค์ ใณ