public Brick SpawnBrick(Brick brick, Vector3 originPos, float moveSpeed, Transform parent = null) { Vector3 spawnPos; Vector3 prevBrickPos = prevBrick.transform.position; if (curAxis == BrickAxis.Z) { curAxis = BrickAxis.X; } else { curAxis = BrickAxis.Z; } if (curAxis == BrickAxis.Z) { spawnPos = originPos + new Vector3(0, prevBrickPos.y + spawnOffsetV, prevBrickPos.z + spawnOffsetH); } else { spawnPos = originPos + new Vector3(prevBrickPos.x - spawnOffsetH, prevBrickPos.y + spawnOffsetV, 0); } Brick newBrick = Instantiate(brick, spawnPos, Quaternion.identity, parent); Color color = colorPicker.GetNextColor(); newBrick.Init(curAxis, color, moveSpeed); return(newBrick); }
public void Init(BrickAxis _axis, Color _color, float speed) { Renderer renderer = GetComponent <Renderer>(); MaterialPropertyBlock propertyBlock = new MaterialPropertyBlock(); propertyBlock.SetColor("_BaseColor", _color); renderer.SetPropertyBlock(propertyBlock); color = _color; movement = new BrickMovement(transform, speed, transform.position, _axis); }
void SetRandomMovement(GameObject go, BrickAxis axis) { float xVel = Random.Range(-4, 4); float yVel = Random.Range(-1, 1); float zVel = Random.Range(-1, 1); if (axis == BrickAxis.Z) { go.GetComponent <Rigidbody>().angularVelocity = new Vector3(xVel, yVel, zVel); } else { go.GetComponent <Rigidbody>().angularVelocity = new Vector3(zVel, yVel, xVel); } }
public BrickMovement(Transform _transform, float _speed, Vector3 _startPos, BrickAxis _axis) { speed = _speed; startPos = _startPos; transform = _transform; axis = _axis; isMoving = true; if (axis == BrickAxis.X) { endPos = new Vector3(-startPos.x, startPos.y, startPos.z); } else { endPos = new Vector3(startPos.x, startPos.y, -startPos.z); } targetPos = endPos; }
public void SetAxis(BrickAxis _axis) { axis = _axis; }
public static CutResult CutBrick(Brick brickToCut, Brick brick, BrickAxis axis, float threshold) { if (axis == BrickAxis.X) { Vector2 brickToCut_A = brickToCut.GetPointByNumber(1); Vector2 brickToCut_B = brickToCut.GetPointByNumber(4); Vector2 brick_A = brick.GetPointByNumber(1); Vector2 brick_B = brick.GetPointByNumber(4); if (brickToCut_B.x < brick_A.x || brickToCut_A.x > brick_B.x) { // Player missed! return(CutResult.Fail(axis)); } if (brickToCut_B.x < brick_B.x) { if (brick_B.x - brickToCut_B.x <= threshold) { return(CutResult.Success(axis)); } else { float newScaleX = (brickToCut_B.x - brick_A.x); float newPosX = brickToCut_B.x - newScaleX / 2; Vector3 brickScale = brickToCut.transform.localScale; brickToCut.transform.localScale = new Vector3(newScaleX, brickScale.y, brickScale.z); Vector3 brickPos = brickToCut.transform.position; brickToCut.transform.position = new Vector3(newPosX, brickPos.y, brickPos.z); Vector3 pieceScale = new Vector3(brick_A.x - brickToCut_A.x, brickScale.y, brickScale.z); Vector3 piecePos = new Vector3(brickToCut_A.x + pieceScale.x / 2, brickPos.y, brickPos.z); return(CutResult.Partial(piecePos, pieceScale, axis)); } } if (brickToCut_A.x > brick_A.x) { if (brickToCut_A.x - brick_A.x <= threshold) { return(CutResult.Success(axis)); } else { float newScaleX = (brick_B.x - brickToCut_A.x); float newPosX = brickToCut_A.x + newScaleX / 2; Vector3 brickScale = brickToCut.transform.localScale; brickToCut.transform.localScale = new Vector3(newScaleX, brickScale.y, brickScale.z); Vector3 brickPos = brickToCut.transform.position; brickToCut.transform.position = new Vector3(newPosX, brickPos.y, brickPos.z); Vector3 pieceScale = new Vector3(brickToCut_A.x - brick_A.x, brickScale.y, brickScale.z); Vector3 piecePos = new Vector3(brick_B.x + pieceScale.x / 2, brickPos.y, brickPos.z); return(CutResult.Partial(piecePos, pieceScale, axis)); } } } if (axis == BrickAxis.Z) { Vector2 brickToCut_A = brickToCut.GetPointByNumber(3); Vector2 brickToCut_B = brickToCut.GetPointByNumber(4); Vector2 brick_A = brick.GetPointByNumber(3); Vector2 brick_B = brick.GetPointByNumber(4); if (brickToCut_B.y > brick_A.y || brickToCut_A.y < brick_B.y) { // Player missed return(CutResult.Fail(axis)); } if (brickToCut_B.y > brick_B.y) { if (brickToCut_B.y - brick_B.y <= threshold) { return(CutResult.Success(axis)); } else { float newScaleZ = (brick_A.y - brickToCut_B.y); float newPosZ = brickToCut_B.y + newScaleZ / 2; Vector3 brickScale = brickToCut.transform.localScale; brickToCut.transform.localScale = new Vector3(brickScale.x, brickScale.y, newScaleZ); Vector3 brickPos = brickToCut.transform.position; brickToCut.transform.position = new Vector3(brickPos.x, brickPos.y, newPosZ); Vector3 pieceScale = new Vector3(brickScale.x, brickScale.y, brickToCut_A.y - brick_A.y); Vector3 piecePos = new Vector3(brickPos.x, brickPos.y, brick_A.y + pieceScale.z / 2); return(CutResult.Partial(piecePos, pieceScale, axis)); } } if (brickToCut_A.y < brick_A.y) { if (brick_A.y - brickToCut_A.y <= threshold) { return(CutResult.Success(axis)); } else { float newScaleZ = (brickToCut_A.y - brick_B.y); float newPosZ = brickToCut_A.y - newScaleZ / 2; Vector3 brickScale = brickToCut.transform.localScale; brickToCut.transform.localScale = new Vector3(brickScale.x, brickScale.y, newScaleZ); Vector3 brickPos = brickToCut.transform.position; brickToCut.transform.position = new Vector3(brickPos.x, brickPos.y, newPosZ); Vector3 pieceScale = new Vector3(brickScale.x, brickScale.y, brick_B.y - brickToCut_B.y); Vector3 piecePos = new Vector3(brickPos.x, brickPos.y, brick_B.y - pieceScale.z / 2); return(CutResult.Partial(piecePos, pieceScale, axis)); } } } return(CutResult.Fail(axis)); }
public static CutResult Partial(Vector3 position, Vector3 scale, BrickAxis axis) { return(new CutResult(true, new CutPiece(position, scale), axis)); }
public static CutResult Success(BrickAxis axis) { return(new CutResult(true, null, axis)); }
public static CutResult Fail(BrickAxis axis) { return(new CutResult(false, null, axis)); }
CutResult(bool _isSuccess, CutPiece _cutPiece, BrickAxis _axis) { isSuccess = _isSuccess; cutPiece = _cutPiece; axis = _axis; }
void Start() { curAxis = BrickAxis.Z; colorPicker = new ColorPicker(); }