// 8方向の障害物を破壊 private void BlowObstacles() { GetComponent <Animator>().SetBool("Special", true); int layerMask = LayerMaskConstant.Hako; Vector3 origin = transform.position + (Vector3)MoveBase.Center; RaycastHit2D[] hits = Physics2D.BoxCastAll(origin - new Vector3(0, Constant.Step * 1.5f + 0.1f, 0), new Vector3(Constant.Step * 1.5f, 0.1f), 0, new Vector2(0, 1), Constant.Step * 3 - 0.1f, layerMask); foreach (var hako in hits) { Debug.Log(hako.collider); HakoMove hMove = hako.collider.GetComponent <HakoMove>(); Map.RemoveObject(hMove.MapPosition); UnityEngine.Object.Destroy(hako.collider.transform.gameObject); } IsActing = true; lastAct = Time.time; ActDuration = 2.0f; }
void pushObstacle(Vector2 dir) { // Rayを飛ばして障害物にぶつかった場合は動かせる // TODO: 現状箱があるかどうかは分かるけどどの箱か特定することができないのでとりあえずRaycastを使う // 箱にコライダーがついてると問題があるようならまた考える Vector2 pos = transform.position; pos = pos + center; int layerMask = LayerMaskConstant.Hako; RaycastHit2D hit = Physics2D.Linecast(pos, pos + dir * Constant.Step, layerMask); RaycastHit2D lastHit = new RaycastHit2D(); Vector2 pPos = GetComponent <ProducerMove>().MapPosition; Vector2 targetMapPosition = pPos + new Vector2(dir.x, -dir.y); bool isHit = false; // 箱にぶつからなくなるまで隣にRayを伝播させる while (Map.IsObstacle(targetMapPosition) && hit.collider.GetComponent <HakoMove>() != null) { isHit = true; pos = pos + dir * Constant.Step; hit = Physics2D.Linecast(pos, pos + dir * Constant.Step, layerMask); targetMapPosition += new Vector2(dir.x, -dir.y); } if (isHit) { lastHit = hit; } if (lastHit.collider != null) { HakoMove hako = lastHit.collider.GetComponent <HakoMove>(); hako.Move(dir); IsActing = true; ActDuration = 0.25f; lastAct = Time.time; } }