English 中文(简体)
i m 目前在ches中与Hover一道面对 p
原标题:i m currently facing a pb with Hover in a chessGame

首先,它产生超大效应,确保它发挥作用,但当它增加投入时,它干扰了 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

问题回答

我认为,这个问题可能与此处的<代码>e有关。

    // Releasing the mouse Button
    if (currentlyDragging != null && Input.GetMouseButtonUp(0))
    {
        //your code
    }
    else
    { 
        if (currentHover != -Vector2Int.one)
        {
            Squares[currentHover.x, currentHover.y].layer = (containsValidMove(ref availableMoves, currentHover)) ? LayerMask.NameToLayer("Highlight") : LayerMask.NameToLayer("Square");
            currentHover = -Vector2Int.one;

            //your code
        }
    }

I am guessing this code is running inside the Update() loop or something similar. Frame 1 the below condition will be true and currentHover will be assined a value:

    if (currentHover == -Vector2Int.one)
    {
        currentHover = hitPosition;
        Squares[hitPosition.x, hitPosition.y].layer = LayerMask.NameToLayer("Hover");
    }

如果你没有释放 mo子,则下一个框架是假的:(目前)。 Dragging ! 输入:GetMouseButtonUp(0),该编码将沿用上文提及的其他声明和if(当Hover !=-Vector2Int.one)

这将最终导致分配到<代码>Layer Mask.NameTo Layer(“Square”)的层层,而目前的 h权被设定为违约值,如果我上述假设是正确的,这一周期将继续。

                Squares[currentHover.x, currentHover.y].layer = (containsValidMove(ref availableMoves, currentHover)) ? LayerMask.NameToLayer("Highlight") : LayerMask.NameToLayer("Square");
            currentHover = -Vector2Int.one;

我无法在当地充分检验这一标准,因为《法典》被搁置,只显示少数背景,因此,我原来的假设完全是假的,但我希望,不管怎样,这还是有帮助的。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签