首先,它产生超大效应,确保它发挥作用,但当它增加投入时,它干扰了 h,在我把一只 h子改变其颜色时,它不会更先见地显示。
RaycastHit info;
Ray ray = currentCamera.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out info, 150, LayerMask.GetMask("Square","Hover","Highlight")))
{
//Get the indexes of the Square you hit
Vector2Int hitPosition = LookUpSquareIndex(info.transform.gameObject);
// From not hovering to hovering
if (currentHover == -Vector2Int.one)
{
currentHover = hitPosition;
Squares[hitPosition.x, hitPosition.y].layer = LayerMask.NameToLayer("Hover");
}
// From hovering one square to hovering another square
if (currentHover != hitPosition)
{
Squares[currentHover.x, currentHover.y].layer = containsValidMove(ref availableMoves, currentHover) ? LayerMask.NameToLayer("Highlight") : LayerMask.NameToLayer("Square");
currentHover = hitPosition;
Squares[hitPosition.x, hitPosition.y].layer = LayerMask.NameToLayer("Hover");
}
//pressing the mouse button
if (Input.GetMouseButtonDown(0))
{
if (chessPieces[hitPosition.x, hitPosition.y] != null)
{
//Is it Our Turn
if ((chessPieces[hitPosition.x, hitPosition.y].team==0 && isWhiteTurn) || (chessPieces[hitPosition.x, hitPosition.y].team == 1 && !isWhiteTurn))
{
currentlyDragging = chessPieces[hitPosition.x, hitPosition.y];
//getting a list of available Moves , heighlight the available moves
availableMoves = currentlyDragging.GetAvailableMoves(ref chessPieces, SQUARE_COUNT_X, SQUARE_COUNT_Y);
//Getting a Special Moves List
specialMove = currentlyDragging.GetSpecialMoves(ref chessPieces, ref moveList, ref availableMoves);
highlightSquares();
}
}
}
// Releasing the mouse Button
if (currentlyDragging != null && Input.GetMouseButtonUp(0))
{
Vector2Int previousPosition = new Vector2Int(currentlyDragging.currentX, currentlyDragging.currentY);
bool validMove = MoveTo(currentlyDragging, hitPosition.x, hitPosition.y);
if (!validMove)
currentlyDragging.setPosition(GetSquaresCenter(previousPosition.x, previousPosition.y));
currentlyDragging = null;
removehighlightSquares();
}
else
{
if (currentHover != -Vector2Int.one)
{
Squares[currentHover.x, currentHover.y].layer = (containsValidMove(ref availableMoves, currentHover)) ? LayerMask.NameToLayer("Highlight") : LayerMask.NameToLayer("Square");
currentHover = -Vector2Int.one;
if (currentlyDragging && Input.GetMouseButtonUp(0))
{
currentlyDragging.setPosition(GetSquaresCenter(currentlyDragging.currentX, currentlyDragging.currentY));
currentlyDragging = null;
removehighlightSquares();
}
}
}
// while dragging a piece
if (currentlyDragging)
{
Plane horizontalePlane = new Plane(Vector3.up , Vector3.up*Yoffset/1000);
float distance = 0.0f;
if(horizontalePlane.Raycast(ray, out distance))
currentlyDragging.setPosition(ray.GetPoint(distance)+Vector3.up*dragOffset);
}
}
i) 努力增加我们处理中的多种职能 HoerEffect and HandleMouseButtonUp and Down