Jump to content
Unity Insider Forum

Rechtecke zeichnen


peachplayer

Recommended Posts

Hallo Leute

Weiss jemand, wie man auf einer 2-dimensionalen Fläche verschiedene Rechtecke zeichnen kann?

Die Rechtecke sollten also auf einer Matrix dargestellt werden.

Habe es mit folgendem Code versucht:

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

public class drawRectangle : MonoBehaviour {

    public Rect[] rec = new Rect[20];
    public Color[] imageOneD = new Color[20]; 
    public Texture aTexture;
    public Material mat;
	// Use this for initialization
	void Start () {

        float offsetX =10.0f;
        float offsetZ = 5.0f;
        float abstandX = 20f;
        float abstandZ = 25f;
        int x; // einfache Zaehlvariable
        int z; // einfache Zaehlvariable
        int k=0; // einfache Zaehlvariable
        float newX;
        float newZ;
 

        for (z = 0; z < 2; z++)
        {
            for (x = 0; x < 10; x++)
            {
                //k = k + 1;
                k = 2*z+x;
                newX = offsetX + x * abstandX;
                newZ = offsetZ + z * abstandZ;
	            rec[k] = new Rect(newX, newZ, Screen.width / 10, Screen.height / 15);
            Debug.Log(rec[k].position.x + " an Position " + newX + " : " + newZ);
           
            }
        }

       
	}
    void OnGUI()
    {
  
        int leftBorder = 10;
        int rightBorder = 10;
        int topBorder = 5;
        int bottomBorder = 5;
        
      
        for (int i = 0; i < 20; i++)
        {
            // Draw colored rectangle
          
              GUI.color = imageOneD[i];

           
            Graphics.DrawTexture (rec[i], aTexture, leftBorder, rightBorder , topBorder , bottomBorder, mat);
        }
    }

Leider klappt das nicht richtig, weil die Rechtecke irgendwie zufällig angeordnet werden statt nebeneinander.

Gruss, peachplayer 

Link zu diesem Kommentar
Auf anderen Seiten teilen

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Gast
Auf dieses Thema antworten...

×   Du hast formatierten Text eingefügt.   Formatierung jetzt entfernen

  Only 75 emoji are allowed.

×   Dein Link wurde automatisch eingebettet.   Einbetten rückgängig machen und als Link darstellen

×   Dein vorheriger Inhalt wurde wiederhergestellt.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Lädt...
×
×
  • Neu erstellen...