简体   繁体   English

如何在unity3d中制作具有这种效果的菜单?

[英]How to make a menu with this effect in unity3d?

Sorry, I'll try to explain better. 抱歉,我会尽力解释。

I want to make a sliding menu where you can select a character. 我想制作一个滑动菜单,您可以在其中选择一个字符。 I want the character that is at the center increases in size to know that this is the current character. 我希望位于中心的字符的大小增加以知道这是当前字符。 The effect can be seen in the game of Crossy Road when you want to select a character. 当您要选择角色时,可以在Crossy Road游戏中看到这种效果。

Sorry but I can't upload a imagen because i am new in the forum 抱歉,由于我是论坛新手,所以我无法上传图片

I think I might be able to help you without needing too much borrowed code. 我想我可以在不需要太多借用代码的情况下为您提供帮助。 There are two possibilities here: 这里有两种可能性:

  1. You have a perspective camera so the "selected" item can just be closer to the camera. 您有一台透视相机,因此“选定”项可以更靠近相机。
  2. You have an orthographic camera so you will have to scale things. 您有一台正交摄影机,因此您必须缩放比例。

For perspective: 透视图:

List<GameObject> characters; //contains all character.
int selectedIndex = 0;      //index to the selected character.
float spacing = 10;         //space between chars

void Update()
{
    if(Input.GetKeyDown("RightArrow"))
    {
        selectIndex++;
        ApplyChanges();
    }

     if(Input.GetKeyDown("LeftArrow"))
    {
        selectIndex--;
        ApplyChanges();
    } 
}

void ApllyChanges()
{
    // Make sure the selected index is within range and then space the characters.
    selectedIndex = selectedIndex % character.Count();
    SpaceCharacters();
}

void SpaceCharacters()
{
    for(int i = 0; i < characters.Count(); ++i)
    {
        // characters on the left will have a negative spacing and so will be placed to the left and vice versa for characters on the right.
        int offset = i - selectedIndex;

        characters[i].transform.position = new Vector3(offset * spacing, 0, 0);
    }
    // Move the selected character closer.
    characters[selectedIndex].transform.position = new Vector3(0,0,spacing);
}

For orthographic camera you will need to set the select characters transform.scale to a larger vector. 对于正交相机,您需要将选择字符transform.scale设置为更大的矢量。

This won't animate anything or look cool. 这不会使任何动画或看起来很酷。 This code will just snap your characters into position. 这段代码只会将您的角色对齐。

The solution I adopted was to attach objects to the transparent buttons in a scrool rect, so as to manage 3d objects with the convenient of scrool rect interface. 我采用的解决方案是将对象附加到scrool rect中的透明按钮上,以便使用scrool rect界面方便地管理3d对象。

Here you can find the official documentation for use scrool rect: http://docs.unity3d.com/Manual/script-ScrollRect.html 在这里您可以找到使用scrool rect的官方文档: http ://docs.unity3d.com/Manual/script-ScrollRect.html

Maybe my assets can serve you ;) 也许我的资产可以为您服务;)

https://www.assetstore.unity3d.com/en/#!/content/60233 https://www.assetstore.unity3d.com/zh/#!/content/60233

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

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