微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

通过Cinemachine动态选择角色

如何解决通过Cinemachine动态选择角色

我正在与一个非常小的团队一起进行一个小型激情项目。我们还不是最擅长C#编码的人,因此我们一直在尝试解决此问题,但运气还不够。

我们想要一个菜单,其中摄像机根据您选择的选项在世界空间中从一个菜单动态移动到另一个菜单,然后进入该菜单,进入字符选择,其中字符发生的情况非常相似

到目前为止,我已经使用Cinemachine正常运行了主菜单,并且按预期工作。但是,当我选择角色时,我遇到了一些问题。我在屏幕上设置了字符选择控件,而不是在世界上使用,以简化操作,但是我一直在尝试弄清楚如何使箭头按钮在各个字符之间切换,同时也可以在到达最终字符时自动循环播放然后再次按下一步。我一直在尝试使用索引进行设置,但一直找不到要使Cinemachine达到我想要的功能所需的麻烦。

有人愿意提供帮助吗?我很感激! c:

我用来完成主菜单代码

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Cinemachine;

public class UITransitionManager : MonoBehavIoUr
{

    public CinemachineVirtualCamera currentCamera;


    public void Start()
    {
        currentCamera.Priority++;
    }


    public void UpdateCamera(CinemachineVirtualCamera target)
    {
        currentCamera.Priority--;

        currentCamera = target;

        currentCamera.Priority++;
    }
}
我尝试进行字符选择的

代码

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Cinemachine;

public class CSelectManager : MonoBehavIoUr
{

    public GameObject[] contestantCams;
    GameObject currentContestant;
    int contestantIndex;
    public Button nextCharacter;
    public Button prevIoUsCharacter;

    void Start() 
    {   
        Button next = nextCharacter.GetComponent<Button>();
        next.onClick.AddListener(TaskOnClickNext);

        Button prev = prevIoUsCharacter.GetComponent<Button>();
        prev.onClick.AddListener(TaskOnClickPrev);
        
        contestantIndex = 0;
        currentContestant = contestantCams[0];
    }

    void TaskOnClickNext()
    {
        Debug.Log("Next character.");
        contestantIndex++;
        if (contestantIndex > (contestantCams.Length - 1))
        {
            contestantIndex = 0;
        }
    }

    void TaskOnClickPrev()
    {
        Debug.Log("PrevIoUs character.");
        contestantIndex--;
        if(contestantIndex < 0)
        {
            contestantIndex = contestantCams.Length - 1;
        }
    }
}


版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。