Attack(임시?) 애니매이션 추가
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
public class PlayerMove : MonoBehaviour
|
||||
{
|
||||
@@ -49,13 +50,51 @@ public class PlayerMove : MonoBehaviour
|
||||
_rigidBody.AddForce(Vector2.right * h, ForceMode2D.Impulse);
|
||||
|
||||
// 유니티6 부터 Velocity에서 LinearVelocity로 변경
|
||||
if (_rigidBody.linearVelocity.x > maxSpeed) // 오른쪽 최대 속도
|
||||
if (_rigidBody.linearVelocityX > maxSpeed) // 오른쪽 최대 속도
|
||||
{
|
||||
_rigidBody.linearVelocity = new Vector2(maxSpeed, _rigidBody.linearVelocity.y);
|
||||
}
|
||||
else if (_rigidBody.linearVelocity.x < maxSpeed * (-1))
|
||||
else if (_rigidBody.linearVelocityX < maxSpeed * (-1))
|
||||
{
|
||||
_rigidBody.linearVelocity = new Vector2(maxSpeed * (-1), _rigidBody.linearVelocity.y);
|
||||
}
|
||||
|
||||
// 플랫폼을 밟고 있을 때
|
||||
if (_rigidBody.linearVelocityY < 0)
|
||||
{
|
||||
Debug.DrawRay(_rigidBody.position, Vector2.down, Color.red);
|
||||
RaycastHit2D rayHit = Physics2D.Raycast(_rigidBody.position, Vector2.down, 0.1f);
|
||||
if(rayHit.collider != null)
|
||||
{
|
||||
// // 바닥에 닿아있을 때 애니메이션 변경
|
||||
if(rayHit.distance < 0.5f)
|
||||
{
|
||||
_animator.SetBool("isJumping", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnCollisionEnter2D(Collision2D collision)
|
||||
{
|
||||
if (collision.gameObject.tag == "Enemy")
|
||||
{
|
||||
// 적과 충돌했을 때
|
||||
OnDameged();
|
||||
Debug.Log("플레이어가 맞았습니다.");
|
||||
}
|
||||
}
|
||||
|
||||
void OnDameged()
|
||||
{
|
||||
// 적과 충돌 후 1초 무적 ( 11번 레이어 PlayerDamaged로 변경 )
|
||||
// 물리 설정에서 PlayerDamaged 레이어와 Enemy 레이어가 충돌하지 않도록 설정함
|
||||
gameObject.layer = 11;
|
||||
|
||||
// 플레이어 HP 감소
|
||||
hp--;
|
||||
|
||||
// 무적 표시
|
||||
_spriteRenderer.color = new Color(1,1,1,0.5f); // 플레이어 반투명
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user