2015-06-14 43 views
0

对不起,我会尽力解释更好。如何在unity3d中制作具有此效果的菜单?

我想制作一个滑动菜单,您可以在其中选择一个角色。我想让位于中心的角色大小增加,以知道这是当前角色。当你想选择一个角色时,可以在Crossy Road的游戏中看到效果。

对不起,但我不能上传imagen画质,因为我是新的论坛

+0

@MickyDuncan对不起,我会试着更好地解释。 我想制作一个滑动菜单,您可以在其中选择一个角色。我想让位于中心的角色大小增加,以知道这是当前角色。当你想选择一个角色时,可以在Crossy Road的游戏中看到效果。 对不起,我不能上传图片,因为我是新的论坛。 – Freddie

+0

谢谢Freddie。您可以通过单击**编辑**来弹出刚才对上述问题所说的内容,从而改善您的问题。这将允许我扭转倒票。谢谢。祝你好运 – MickyD

回答

0

我想我也许能帮助你无需太多借来的代码。这里有两种可能性:

  1. 你有一个透视相机,所以“选择”项目可以更接近相机。
  2. 你有一个正交相机,所以你将不得不规模的东西。

对于观点:

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); 
} 

对于正交相机,你将需要设置选择字符transform.scale到一个更大的载体。

这不会动画或看起来很酷。这段代码只会将你的角色折叠到位。