// Update is called once per frame void Update() { var box = colidbox.transform.position; //transform.Translate(direction * speed * d_t * 15); if (Vector3.Distance(this.transform.position, Body.transform.position) > 10) { Destroy(gameObject); } //충돌관리 Ray2D ray = new Ray2D(box, new Vector2(1, 0)); RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction); if (Physics2D.Raycast(ray.origin, ray.direction, 0.1f) && hit.collider.tag == "map") { blocks.Play(); Destroy(gameObject); } if (Physics2D.Raycast(ray.origin, ray.direction, 0.1f) && hit.collider.tag == "enemy") { Enemy_Control e_c = hit.collider.gameObject.GetComponent <Enemy_Control>(); Enemy_head_control h_c = hit.collider.gameObject.GetComponent <Enemy_head_control>(); if (e_c != null) { e_c.hit_damage(damage); } if (h_c != null) { h_c.hit_damage(damage); } Instantiate(Hit_fx, this.transform.position, Quaternion.identity); // Debug.Log("hit"); Destroy(gameObject); } if (Physics2D.Raycast(ray.origin, ray.direction, 0.1f) && hit.collider.tag == "player") { Enemy_Control e_c = hit.collider.gameObject.GetComponent <Enemy_Control>(); Enemy_head_control h_c = hit.collider.gameObject.GetComponent <Enemy_head_control>(); if (e_c != null) { e_c.hit_damage(damage); } if (h_c != null) { h_c.hit_damage(damage); } Instantiate(Hit_fx, this.transform.position, Quaternion.identity); Debug.Log("hit"); Destroy(gameObject); } }
// Use this for initialization void Start() { e_b = gameObject.transform.parent.gameObject; e_c = e_b.GetComponent <Enemy_Control>(); }