Home > Net >  Need help fixing code to swap camera positions in Unity3D with C#
Need help fixing code to swap camera positions in Unity3D with C#

Time:03-28

I'm revising a code so that a camera will cycle through 3 different locations on a ship. The problem I've come across with this code is that it will only go to a 2nd location & stays there. It needs to cycle through but doesn't.

This is the code I'm working with:

    public void CycleCameraView (Vector3 inputValue, int customPlayerInputEventType)
    {
        // Cycle the current camera view index to the next view.
        currentCameraViewIndex = (currentCameraViewIndex   1) % 3;

        SetCurrentView(currentCameraViewIndex);
    }

    public int GetCurrentCameraViewIndex ()
    {
        return currentCameraViewIndex;
    }

    public int GetNextCameraViewIndex ()
    {
        return (currentCameraViewIndex   1) % 3;
    }

    public void SetCurrentView(int viewIndex)
    {
        if (viewIndex >= 0 && viewIndex < 3 && shipCameraModule != null)
        {
            currentCameraViewIndex = viewIndex;

            if (currentCameraViewIndex == 0)
            {
                // Camera view 1
                // Set the camera parameters to match camera view 1
                
            }
            else if (currentCameraViewIndex == 1)
            {
                // Camera view 2
                // Set the camera parameters to match camera view 2
         
                
            }
            else
            {
                // Camera view 3
                // Set the camera parameters to match camera view 3
                
            }
        }
    }

    #endregion
}

CodePudding user response:

This code needs fixing

public int GetNextCameraViewIndex ()
    {
        return currentCameraViewIndex;
    }

CodePudding user response:

I think we need more stuff if you want us to be able to help you mate. Also, you shouyld definitly use a switch in your SetCurrentView(int viewIndex)

  • Related