Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        RaycastHit2D ray = Physics2D.Raycast(transform.position, transform.right, distance, isLayer);

        if (ray.collider != null)
        {
            Debug.Log("땅");
            if (ray.collider.tag == "Enemy")
            {
                EnemyMove enemyMove = ray.collider.transform.GetComponent <EnemyMove>();
                enemyMove.OnDamaged();
            }
            else if (ray.collider.tag == "Player2")
            {
                Debug.Log("명중!");
                Player2Move player = ray.collider.transform.parent.GetComponent <Player2Move>();
                player.OnDamaged();
            }
            DestroyBullet();
        }

        if (transform.rotation.y == 0)
        {
            transform.Translate(transform.right * speed * Time.deltaTime);
        }
        else
        {
            transform.Translate(transform.right * -1 * speed * Time.deltaTime);
        }
    }
Ejemplo n.º 2
0
 // Update is called once per frame
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (collision.gameObject.tag == "Player")
     {
         //원위치로
         player.OnDamaged();
     }
     if (collision.gameObject.tag == "Player2")
     {
         player2.OnDamaged();
     }
 }
Ejemplo n.º 3
0
 void OnCollisionEnter2D(Collision2D collision)
 {
     // 이부분 수정
     if (collision.gameObject.tag == "Enemy")
     {
         if (rigid.velocity.y < 0 && transform.position.y > collision.transform.position.y)
         {
             OnAttack(collision.transform);
         }
         if (anim.GetBool("is_sword_attack") || anim.GetBool("is_sword_jump_attack"))
         {
             OnAttack(collision.transform);
         }
         else
         {
             OnDamaged();
         }
     }
     else if (collision.gameObject.tag == "Player2")
     {
         if (rigid.velocity.y < 0 && transform.position.y > collision.transform.position.y)
         {
             rigid.AddForce(Vector2.up * 10, ForceMode2D.Impulse);
             Player2Move player = collision.transform.GetComponent <Player2Move>();
             player.OnDamaged();
         }
         if (anim.GetBool("is_sword_attack") || anim.GetBool("is_jump_sword_attack"))
         {
             Debug.Log("칼빵");
             Player2Move player = collision.transform.GetComponent <Player2Move>();
             player.OnDamaged();
         }
     }
     else if (collision.gameObject.tag == "trap")
     {
         OnDamaged();
     }
 }