Unity将3种风格的游戏匹配过程与画布图像匹配

时间:2017-08-25 09:01:11

标签: c# image unity3d canvas

我正在制作像宝石迷阵游戏一样的游戏。我使用画布,我的游戏对象是画布图像。游戏开始时,我的对象在网格中正确,但我不知道如何匹配和销毁相同类型的对象(图像)。

我可以使用哪种代码块?

这是结构:

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

public class DynamicGrid : MonoBehaviour {

    public int col, row;
    public Image[] prefabs = new Image[6];
    private Image image;

    // Use this for initialization
    void Start () {

        RectTransform parent = gameObject.GetComponent<RectTransform> ();
        GridLayoutGroup grid = gameObject.GetComponent<GridLayoutGroup> ();

        grid.cellSize = new Vector2 (parent.rect.width / col, parent.rect.height / row);   //grid cell size (ex: 4x4 - 3x5 etc.)

        for (int i = 0; i < row; i++) {   //fill the rows
            for (int j = 0; j < col; j++) {   //fill the columns
                int num = UnityEngine.Random.Range (0, prefabs.Length);   //select a random number (from 0 to 6 each numbers for each different jewel images)
                image = (Image)Instantiate (prefabs[num]);   //create the randomly seleceted image
                image.transform.SetParent (transform, false);
            }
        }
    }

    // Update is called once per frame
        void Update () {

    }

}

1 个答案:

答案 0 :(得分:0)

以下链接可能对您有所帮助:https://dgkanatsios.com/2015/02/25/building-a-match-3-game-in-unity-3/

查看功能 GetMatches