2016-03-22 24 views
-1

Unity ve programlama konusunda yeniyim ve bu oyunu oyun tahtası üzerinde hareketli arabalarla yapmaya çalışıyorum. Benim fikrim, bir dizi oluşturmak ve bu dizide her öğe veya döşeme hakkında bilgi depolamaktır. Bu karoların daha sonra referans alınabilmesini istiyorum. Belirli bir döşemede GO'nun olup olmadığını tespit etmek, vb. Ne yazık ki, bilgiyi bir karoya tam olarak nasıl kaydederim diye uğraşırdım, böylece daha sonra referans olarak kullanabilmem gerekir. Bu döşemenin dolu olup olmadığını tespit edin. Tüm önerileriniz için şimdiden teşekkür ederiz!C ile Unity'de 2D oyun tahtası/ızgara oluşturma C#

+0

Maalesef biz you.Please için kod bu bir gibi bazı masa oyunu öğreticiler aramaya yazamıyor: https://unity3d.com/learn/tutorials/projects/2d-roguelike/boardmanager –

cevap

0

Aşağıdaki kod, bir panel kontrolüne düğmeler ekler. Oyunlarınızda kullanmak için düğmeyi resimle değiştirebilirsiniz.

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Windows.Forms; 

namespace WindowsFormsApplication1 
{ 
    public partial class Form1 : Form 
    { 
     const int ROWS = 10; 
     const int COLS = 15; 
     const int WIDTH = 20; 
     const int HEIGHT = 20; 
     const int SPACE = 10; 
     List<List<MyButton>> buttons = new List<List<MyButton>>(); 
     public Form1() 
     { 
      InitializeComponent(); 

      for (int row = 0; row < ROWS; row++) 
      { 
       List<MyButton> newRow = new List<MyButton>(); 
       buttons.Add(newRow); 

       for (int col = 0; col < COLS; col++) 
       { 
        MyButton newButton = new MyButton(); 
        newRow.Add(newButton); 

        newButton.Width = WIDTH; 
        newButton.Height = HEIGHT; 
        newButton.Left = col * (WIDTH + SPACE); 
        newButton.Top = row * (HEIGHT + SPACE); 

        newButton.row = row; 
        newButton.col = col; 

        panel1.Controls.Add(newButton); 
       } 
      } 


     } 
    } 
    public class MyButton : Button 
    { 
     public int row { get; set; } 
     public int col { get; set; } 
    } 
}