private void SpawnMatrix() { float xDiffValue = 0; float yDiffValue = 0; string namePos; for (int i = 0; i < 10; i++) { yDiffValue = (4.5f - i); for (int j = 0; j < 10; j++) { xDiffValue = (j - 4.5f); namePos = i.ToString() + " : " + j.ToString(); posObject = MatrixPosition[i, j]; posObject = new GameObject(namePos).transform; posObject.SetParent(matrixParentTransform); posObject.position = new Vector3(xDiffValue * distanceSpawn, yDiffValue * distanceSpawn, 0); posObject.tag = GameObjectTag.Instance().TCells; posObject.gameObject.AddComponent <SpriteRenderer>().sprite = SquareImg; posObject.GetComponent <SpriteRenderer>().color = new Color(0.1f, 0.3f, 0.5f, 1); posObject.gameObject.AddComponent <BoxCollider2D>().isTrigger = true; posObject.gameObject.AddComponent <Rigidbody2D>().gravityScale = 0; MatrixPosition[i, j] = posObject; } } }
private void OnTriggerExit2D(Collider2D other) { if (other.transform.tag == GameObjectTag.Instance().TCells) { RemoveMyBitsToMatrixPos(); } }
private void OnTriggerEnter(Collider other) { if (other.transform.tag == GameObjectTag.Instance().TCells) { originColorBit = other.gameObject.GetComponent <SpriteRenderer>().color; } }
private void OnTriggerStay2D(Collider2D other) { if (other.transform.tag == GameObjectTag.Instance().TCells) { distanceCollision = Vector3.Distance(transform.position, other.transform.position); if (distanceCollision < diagonalScale) { RemoveMyBitsToMatrixPos(); GetFirstBitPosInMatrix1010(other.transform); InsertMyBitsToMatrixPos(); } } }