//Grabs the height and width provided from the GridCreation script and sets its //own size to match that. Adjusts its collider public virtual void ChangeTransform(float height, float width) { if (grid == null) { grid = GameObject.FindGameObjectWithTag("Grid").GetComponent <GridCreation>(); } //adjust position to match up location based up the indexs it has rectTrans = GetComponent <RectTransform>(); if (rectTrans != null) { rectTrans.sizeDelta = new Vector2(width, height); Vector2 pos = grid.ReturnPositionFromIndex(hIndex, wIndex); rectTrans.localPosition = pos; } //adjust its collider to match the new size of the object //the reason that the minus 2s are there are to provide a bit //of leeway on collisions. If the colliders feel a bit too big //players get frustrated: "I totally dodged that!" //if they are on the smaller size, you get the opposite effect //players get excited: "I can't believe I dodged that!" BoxCollider2D box = GetComponent <BoxCollider2D>(); if (box != null) { box.size = new Vector2(width - 2f, height - 2f); } }
void Start() { gridCreation = GameObject.Find("Grid").GetComponent <GridCreation>(); algorithm = gameObject.GetComponent <Algorithm>(); tileSize = viewSize.x / tileAmountX; tileAmountY = (int)System.Math.Ceiling(viewSize.y / tileSize); gridCreation.InitializeGrid(tile, tileSize); }
void Start() { audioSource = GetComponent <AudioSource> (); gridCreation = GameObject.Find("Grid").GetComponent <GridCreation> (); ChangeToggleGroup toggleGroup = GameObject.Find("TopPanel").GetComponent <ChangeToggleGroup> (); toggleGroup.OnChange += toggleGroup_OnChange; // Uncomment next line to play multi sound InvokeRepeating("playMulti", 1f, 1f); }
public override void OnInspectorGUI() { DrawDefaultInspector(); GridCreation gridCreation = (GridCreation)target; if (GUILayout.Button("Create Grid")) { gridCreation.BuildGrid(Handles.GetMainGameViewSize()); } if (GUILayout.Button("Destory Grid")) { gridCreation.DeleteGrid(); } }
void Start() { gameManager = GameObject.Find("GameManager").GetComponent <GameManager>(); gridCreation = GameObject.Find("Grid").GetComponent <GridCreation>(); }
//Grab the grid to make sure it does grab a connection with an object that doesn't exist in scene public void SetGrid(GridCreation grid) { this.grid = grid; GridCreation.GridAdjusted += ChangeTransform; }