Hi there! I’m editing this question…
I came to understand that the Rect class has a very valuable Function called Contains, which I’d like to use.
My problem is that the matrix I use to build those Rects has X,Z coordinates, and when I pass them to a Rect my Zs become Ys.
I just need a Class that holds 4 Vector3s as vertices, without meshes or other stuff. I could build up my own one but that Cointains function would require me some extra work ( since my skills are halfway to acceptability).
Is there something else I can use to achieve this goal or maybe a way to build Rects with coordinates I want? Maybe inheriting from Rect/similar and then…? Thanks for the patience!
EDIT + added comments
This is what I’ve got so far, if you’re interested in commenting ( I’d like some suggestions about the code because I’m a self taught “programmer” and I don’t know if my way is canon or utterly twisted):
using UnityEngine;
using System.Collections;
[System.Serializable]
public class RectZ{
//Do you like Rects? Would you like them to be X,Z and Y,Z too? Then you'll love this!
public float wMIn; //minimum width... sort of base
public float wMAx; //maximum width
public float hMIn; //minimum height
public float hMAx; //maximum height
public Vector3 center; //the center of this RectZ
public Vector3 size; //the size
public Vector3 extents; //..........
public Vector3 worldCoordinates; //.... pretty straightforward ain't it?
//SO...
//To build a new RectZ from another script, you pass these parameters inside its constructor...
public RectZ (float _UpMinVertex, float _UpMaxVertex, float _DownMinVertex, float _DownMaxVertex, int _1xy_2xz_3yz){
wMIn = _UpMinVertex;
wMAx = _UpMaxVertex;
hMIn = _DownMinVertex;
hMAx = _DownMaxVertex;
//I use an INT as a BOOL to understand which axes you want... this makes the call easier
if(_1xy_2xz_3yz == 1){
size = new Vector3(wMAx-wMIn,hMAx-hMIn,0);
extents = new Vector3(size.x/2,size.y/2,0);
center = new Vector3(size.x-extents.x,size.y-extents.y,0);
worldCoordinates = new Vector3(wMIn+center.x,hMIn+center.y,0);
}
if(_1xy_2xz_3yz == 2){
size = new Vector3(wMAx-wMIn,0,hMAx-hMIn);
extents = new Vector3(size.x/2,0,size.z/2);
center = new Vector3(size.x-extents.x,0,size.z-extents.z);
worldCoordinates = new Vector3(wMIn+center.x,0,hMIn+center.z);
}
if(_1xy_2xz_3yz == 3){
size = new Vector3(0,wMAx-wMIn,hMAx-hMIn);
extents = new Vector3(0,size.y/2,size.z/2);
center = new Vector3(0,size.y-extents.y,size.z-extents.z);
worldCoordinates = new Vector3(0,wMIn+center.y,hMIn+center.z);
}
}
}
To call it I just type things like this:
RectZ cell = new RectZ(vertex.x,vertex.x+tileSize,vertex.z,vertex.z+tileSizeZ,2);
I’ve skipped other functions of RectZ because I haven’t tested them yet, but I’ll update them as I progress.
This thing, called using my matrix X,Z, works!