简体   繁体   English

需要帮助修复代码以交换 Unity3D 和 C# 中的相机位置

[英]Need help fixing code to swap camera positions in Unity3D with C#

I'm revising a code so that a camera will cycle through 3 different locations on a ship.我正在修改代码,以便摄像机可以循环通过船上的 3 个不同位置。 The problem I've come across with this code is that it will only go to a 2nd location & stays there.我在使用这段代码时遇到的问题是它只会将 go 发送到第二个位置并停留在那里。 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
}

First, you are repeating your code here which is obviously not a good practice.首先,您在这里重复您的代码,这显然不是一个好习惯。

(currentCameraViewIndex + 1) % 3;

Call the GetNextCameraViewIndex and bring the above logic there.调用 GetNextCameraViewIndex 并将上述逻辑放在那里。

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



public int GetNextCameraViewIndex ()
    {
        return (currentCameraViewIndex + 1) % 3; // Please correct if required, I'm not on a dev machine.
    }

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)此外,您应该在 SetCurrentView(int viewIndex) 中明确使用开关

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM