private void DashOnEnd() { MapDoor mapDoor = GetComponent <UsrControl>().dashTarget; if (mapDoor == null || Mathf.Abs(transform.position.y - mapDoor.transform.position.y) > state.doorDistance)//y轴再次确认 { DashFail(); return; } Vector2 colliderPos = new Vector2(transform.position.x, transform.position.y) + state.boxCollider2D.offset; Vector2 endColliderPos = colliderPos + state.currentDir * mapDoor.dashDistance - new Vector2(0, -0.1f); Collider2D hit = Physics2D.OverlapBox(endColliderPos, state.boxCollider2D.size, 0, 1 << LayerMask.NameToLayer("solid") | 1 << LayerMask.NameToLayer("wall") | 1 << LayerMask.NameToLayer("door")); if (hit == null || hit.GetComponent <PlatformEffector2D>()) //瞬移目标位置无碰撞 { mapDoor.SetDash(state); Transform tempTarget = transform.Find("Camera Target"); tempTarget.parent = mapDoor.transform; tempTarget.localPosition = state.startCameraTargetLocalPos; } else { state.SafeRealseDoor(mapDoor); mapDoor.DisAppear(); DashFail(); } state.isOnMove = false; }
public bool Create() { if (myCreate != null) //回收 { state.SafeRealseDoor(myCreate); myCreate.DisAppear(); return(false); } if (state.goldenKeyTime <= 0 && state.greenKey <= 0) //钥匙不足 { GetComponent <UsrAniCallBack>().ErrorSound(); return(false); } Vector2 colliderPos = new Vector2(transform.position.x, transform.position.y) + state.boxCollider2D.offset; Vector2 endColliderPos = colliderPos + state.currentDir * state.createDistance - new Vector2(0, -0.1f); Collider2D hit = Physics2D.OverlapBox(endColliderPos, state.boxCollider2D.size, 0, 1 << LayerMask.NameToLayer("solid") | 1 << LayerMask.NameToLayer("wall") | 1 << LayerMask.NameToLayer("door")); if (hit != null && !hit.GetComponent <PlatformEffector2D>()) { GetComponent <UsrAniCallBack>().ErrorSound(); return(false); } GameObject temp = Instantiate(pbDoor, (Vector2)transform.position + state.currentDir * state.createDistance, Quaternion.identity); temp.transform.parent = GameObject.Find("MapManager").transform; myCreate = temp.GetComponent <MapDoor>(); myCreate.SetColorA(0); if (state.goldenKeyTime > 0) { myCreate.reCollectable = false; } else { myCreate.reCollectable = true; state.UseGreenKey(); } return(true); }