【问题标题】:Unity match 3 style game matching process with canvas imagesUnity match 3 风格游戏匹配过程与画布图像
【发布时间】:2017-08-26 17:47:41
【问题描述】:

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

我可以使用什么样的代码块?

这是结构:

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 () {

    }

}

【问题讨论】:

  • 我尝试了多维图像数组 Image[i,j] 来保留图像而不是图像变量,但我得到了错误。如果我可以将图像保存在多维数组中,也许我可以使用 for 循环与邻居进行比较。你有更好的主意吗?
  • 尝试为您的逻辑使用多维 int 数组而不是 Image 数组。对于显示,只需将数字与图像匹配
  • 我试过了,但是如何将数字与图像匹配?

标签: c# image unity3d canvas


【解决方案1】:

这里有一个可能对您有帮助的链接:https://dgkanatsios.com/2015/02/25/building-a-match-3-game-in-unity-3/

看看函数GetMatches

【讨论】:

    猜你喜欢
    • 2016-01-10
    • 2023-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-21
    • 1970-01-01
    • 2017-07-12
    • 1970-01-01
    相关资源
    最近更新 更多