์ ํ”„ํ‚น ๋น„์Šค๋ฌด๋ฆฌํ•œ ๊ฒŒ์ž„ ๋งŒ๋“ค๊ณ  ์žˆ๋Š”๋ฐ

๊ฐ€๋”์”ฉ ์ง€ ํ˜ผ์ž ใ…ˆใ„ด ๋นจ๋ผ์ ธ์š”...

๋ญ” ๋ฒ„๊ทผ์ง€ ๋ชจ๋ฅด๊ฒ ๋Š”๋ฐ ์™œ ์ด๋Ÿด๊นŒ์š”?




using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using UnityEngine.SceneManagement;


public class PlayerController : MonoBehaviour

{

ย  ย  Rigidbody2D rigid2D;

ย  ย  Animator animator;

ย  ย  float jumpForce = 680.0f;

ย  ย  float walkForce = 20.0f;

ย  ย  float maxWalkSpeed = 2.0f;


ย  ย  void Start()

ย  ย  {

ย  ย  ย  ย  this.rigid2D = GetComponent<Rigidbody2D>();

ย  ย  ย  ย  this.animator = GetComponent<Animator>();

ย  ย  }


ย  ย  void Update()

ย  ย  {


ย  ย  ย  ย  if (Input.GetKeyDown(KeyCode.Space) && this.rigid2D.velocity.y == 0)

ย  ย  ย  ย  {

ย  ย  ย  ย  ย  ย  this.animator.SetTrigger("JumpTrigger");

ย  ย  ย  ย  ย  ย  this.rigid2D.AddForce(transform.up * this.jumpForce);

ย  ย  ย  ย  }


ย  ย 

ย  ย  ย  ย  int key = 0;

ย  ย  ย  ย  if (Input.GetKey(KeyCode.RightArrow)) key = 1;

ย  ย  ย  ย  if (Input.GetKey(KeyCode.LeftArrow)) key = -1;



ย  ย  ย  ย  float speedx = Mathf.Abs(this.rigid2D.velocity.x);



ย  ย  ย  ย  if (speedx < this.maxWalkSpeed)

ย  ย  ย  ย  {

ย  ย  ย  ย  ย  ย  this.rigid2D.AddForce(transform.right * key * this.walkForce);

ย  ย  ย  ย  }


ย  ย  ย  ย  // ์›€์ง์ด๋Š” ๋ฐฉํ–ฅ์— ๋”ฐ๋ผ ์ด๋ฏธ์ง€ ๋ฐ˜์ „

ย  ย  ย  ย  if (key != 0)

ย  ย  ย  ย  {

ย  ย  ย  ย  ย  ย  transform.localScale = new Vector3(key, 1, 1);

ย  ย  ย  ย  }



ย  ย  ย  ย  if (this.rigid2D.velocity.y == 0)

ย  ย  ย  ย  {

ย  ย  ย  ย  ย  ย  this.animator.speed = speedx / 2.0f;

ย  ย  ย  ย  }

ย  ย  ย  ย  else

ย  ย  ย  ย  {

ย  ย  ย  ย  ย  ย  this.animator.speed = 1.0f;

ย  ย  ย  ย  }


ย  ย  ย  ย  if (transform.position.y < -36)

ย  ย  ย  ย  {

ย  ย  ย  ย  ย  ย  SceneManager.LoadScene("GameScene");

ย  ย  ย  ย  }

ย  ย  }


ย  ย  void OnTriggerEnter2D(Collider2D other)

ย  ย  {

ย  ย  ย  ย  Debug.Log("๊ณจ");

ย  ย  ย  ย  SceneManager.LoadScene("ClearScene");

ย  ย  }

}