void OnCollisionExit2D(Collision2D collision)
{
// 땅에서 벗어나면 isGrounded를 false로 설정
if (collision.gameObject.CompareTag("Ground"))
{
isGrounded = false;
}
// 문에서 떠나면 이동 가능 상태 해제
if (collision.gameObject.CompareTag("Key1")||collision.gameObject.CompareTag("Key2"))
{
canMoveToNextStage = false;
}
}
//키 생성
void InstantiateKey()
{
//키 활성화
keyPrefab.SetActive(true);
}
void Die()
{
isDie = true;
rigid.velocity = Vector3.zero;
//die mothion
animator.Play("Die");
//falling
BoxCollider2D[] colls = gameObject.GetComponents<BoxCollider2D>();
colls[0].enabled = false;
colls[1].enabled = false;
//die bound
Vector2 dieVelocity = new Vector2(0, 10f);
rigid.AddForce(dieVelocity, ForceMode2D.Impulse);
//RESTART STAGE
Invoke("RestartStage", 2f);
}
void RestartStage()
{
//stopgame
Time.timeScale = 0f;
//reload stage
}
private void OnTriggerEnter2D(Collider2D collider)
{
Debug.Log("충돌함");
if (collider.CompareTag("Enemy"))
{
Debug.Log("충돌함");
if (collider.gameObject.tag == "Enemy" || !collider.isTrigger && !(rigid.velocity.y < -10f))
{
//bouncing
Vector2 attackedvelocity = Vector2.zero;
if (collider.gameObject.transform.position.x > transform.position.x)
attackedvelocity = new Vector2(-2f, 7f);
else
attackedvelocity = new Vector2(2f, 7f);
rigid.AddForce(attackedvelocity, ForceMode2D.Impulse);
health--;
Debug.Log("충돌함");
}
}
/* if (other.gameObject.tag == "Ground")
{
health = 0;
}*/
if(health > 1)
isUnBeatTime = true;
StartCoroutine("UnBeatTime");
{
}
IEnumerator UnBeatTime()
{
int countTime = 0;
while (countTime < 10)
{
//alpha effect
if (countTime % 2 == 0)
renderer.color = new Color32(255, 255, 255, 90);
else
renderer.color = new Color32(255, 255, 255, 180);
//wait update frame
yield return new WaitForSeconds( 1f);
countTime++;
}
renderer.color = new Color32(255, 255, 255, 255);
//unbeattime off
isUnBeatTime = false;
yield return null;
}
}
rigid 컴포넌트랑 collider 컴포넌트까지 다 확인 했는데 게임 세팅 옵션이랑 하아...
Enemy가 트리거임?
귀여워
OnTriggerEnter2D 자체가 호출이 안되는거면 리지드, 트리거 설정이 잘못됐거나 물리연산 처리를 update에서 했거나지뭐