Hello Unity Community,
I’ve been working on static variables and array methods. Therefor I wrote a code piece which Works nice with one collider but it has problems when i add two…
Our Block Object’s script
//Object's color variable.
var objectColor : String;
//Object's Unique ID.
var objectID : String;
//At first...
function Start () {
objectID = (RandomColorGenerator.selectedColor.ToString() + Spawning.spawnCount.ToString());
objectColor = RandomColorGenerator.selectedColor;
gameObject.GetComponent(SpriteRenderer).color = RandomColorGenerator.color;
gameObject.name = objectID;
}
function OnTriggerEnter2D(rowCollider : Collider2D) {
var blocksIdArray = rowCollider.gameObject.GetComponent(RowScript).blocksIdArray;
var blocksColorArray = rowCollider.gameObject.GetComponent(RowScript).blocksColorArray;
if(rowCollider.gameObject.tag == "Row") {
rowCollider.gameObject.GetComponent(RowScript).blocksIdArray.Push(objectID);
rowCollider.gameObject.GetComponent(RowScript).blocksColorArray.Push(objectColor);
}
}
and our row’s array script
//Variable for blocks ID array
public static var blocksIdArray = Array();
//Variable for observing.
var blocksIdArrayInspector : String[];
//Variable for blocks color array
public static var blocksColorArray = Array();
//Variable for observing.
var blocksColorArrayInspector : String[];
function Start() {
blocksColorArray.Clear();
blocksIdArray.Clear();
}
function Update() {
blocksColorArrayInspector = blocksColorArray;
blocksIdArrayInspector = blocksIdArray;
}
now when i do this;
My Cyan block collides with collider 6, not 7 but, they have same script. Why this problem happens ? Does anyone have any idea ?