我目前正在Unity3D上制作游戏,您必须单击颜色对才能匹配它们,然后消失。我正在使用2D精灵来做到这一点,但当我们通过鼠标点击鼠标时,我正在努力消除这个对。Unity 3D - 匹配对(2D)游戏
点击黄色,然后再次点击黄色,使两者都消失。 (直到板被清除或颜色。)
如果点击黄色,黄色以外的任何东西都不会做任何事情。
在此先感谢。
这里是精灵的布局看起来像:
难道是最好给每一个颜色的标签?
这就是我想要发生的事情:当游戏开始时,它从6个数组中选取3种颜色,然后随机将它们(每种颜色2种)放在屏幕上。然后你必须点击颜色,例如绿色(它会突出显示),然后点击其他绿色,它们都会消失。如果你想先点击绿色然后点击黄色,游戏就会结束。
这是我目前已经实现了代码:
// [...]
if (Input.GetMouseButtonDown(0))
{
CastRay();
}
}
function CastRay() {
var ray: Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
var hit: RaycastHit2D = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
if(hit.collider != null)
{
// Number is the amount of objects on the screen at one time.(6)
number --;
//Test to see if a mouse click interacts with the 2D Sprite.(Then destroys it)
Debug.Log ("Target Position: " + hit.collider.gameObject.transform.position + gameObject.tag);
Destroy(hit.collider.gameObject);
}
// This when the number hits 0 the level restarts (To check random elements)
if (number == 0)
{
Application.LoadLevel (0);
}
}
嗨,这将有助于人们试图理解和解决你的问题,如果你可以包括你目前的实现(到目前为止您已经尝试过的代码),并且可能会添加关于您认为逻辑应该是什么的评论。然后,解释它如何不能达到你的目标(即不正确的行为)。 – Serlite
我已更新我的问题@Serlite谢谢! – taiomi