【发布时间】:2016-06-22 20:44:09
【问题描述】:
我目前正在开发 Unity3D 游戏,您必须单击颜色对来匹配它们,然后它们就会消失。我正在使用 2D sprites 来执行此操作,但在通过鼠标单击两者时擦除这对的逻辑方面我正在苦苦挣扎。
单击黄色,然后再次单击黄色以使两者消失。 (直到板子被清除或着色。)
如果点击黄色,那么除了黄色之外的任何东西都不会做任何事情。
提前致谢。
下面是精灵的布局:
最好给每种颜色一个标签吗?
这就是我想要发生的事情:当游戏开始时,它会从 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);
}
}
【问题讨论】:
-
您好,如果您可以包含您当前的实现(到目前为止您尝试过的代码),并且可能会在其中添加有关您的内容的 cmets,这将对试图理解和解决您的问题的人们有所帮助认为逻辑应该是。然后,解释它如何无法实现您的目标(即不正确的行为)。
-
我已经更新了我的问题@Serlite 谢谢!
标签: unity3d 2d unityscript