public void mouseHover() { //(wip) this function will update the mouse selection //--------Player Code---------------------------- if (Grid_Turn_Manager.isEnemyTurn == false) // will keep the player from selecting anything during the enemies turn { e_isAxisInUse = false; var ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { if (lastHitObject != null && lastHitObject != hit.collider.transform) { //if the lastHitObject is not null and different from the current hit object then //reset the material of the lastHitObject script = lastHitObject.GetComponent <Grid_Unit_Script>(); if (script != null) { script.selection.SetActive(false); } } lastHitObject = hit.collider.transform; //change the hit objects material; script = lastHitObject.GetComponent <Grid_Unit_Script>(); if (script != null) { selectedGridUnit.x = script.x; selectedGridUnit.y = script.y; selectedGridUnit.z = script.z; script.selection.SetActive(true); } } else if (lastHitObject) { //reset the material of the lastHitObject if the raycast fail; script = lastHitObject.GetComponent <Grid_Unit_Script>(); if (script != null) { script.selection.SetActive(false); } } } else if (Grid_Turn_Manager.isEnemyTurn == true) { //------------Enemy Code-------------------------------- if (e_isAxisInUse == false) { // Call your event function here. if (script != null) { script.selection.SetActive(false); } e_isAxisInUse = true; } } }
public void GenerateGrid(int rows = 2, int columns = 2, int layers = 1, int startX = 0, int startY = 0, int startZ = 0, int unitSpacing = 2) { //this function generates a grid using its given variables int x = startX, y = startY, z = startZ; for (int l = 0; l < layers; l++) { x = startX; for (int r = 0; r < rows; r++) { z = startZ; for (int c = 0; c < columns; c++) { Transform gridUnitPrefabClone = Instantiate(gridUnitPrefab, new Vector3(x, y, z), Quaternion.LookRotation(Vector3.down, Vector3.up), gridHolder); Grid_Unit_Script gridUnitPrefabCloneScript = gridUnitPrefabClone.GetComponent <Grid_Unit_Script>(); gridUnitPrefabCloneScript.x = x - startX; gridUnitPrefabCloneScript.x = gridUnitPrefabCloneScript.x / unitSpacing; gridUnitPrefabCloneScript.y = y - startY; gridUnitPrefabCloneScript.y = gridUnitPrefabCloneScript.y / unitSpacing; gridUnitPrefabCloneScript.z = z - startZ; gridUnitPrefabCloneScript.z = gridUnitPrefabCloneScript.z / unitSpacing; z += unitSpacing; numOfGridUnits++; if (debugLogs_01) { print("The current number of grid units is " + numOfGridUnits + " units."); } } x += unitSpacing; } y += unitSpacing; } if (debugLogs_01 || debugLogs_02) { print("The total number of grid units should be " + numOfGridUnits + " units."); } }
public void ai_mouseHover(int x, int y, int z, bool unselect = false) {//(wip) this function will update the mouse selection if (unselect == false) { Grid_Character_Movement Grid_Character_Movement = new Grid_Character_Movement(); GameObject g = Grid_Character_Movement.findGridUnitByCordinate(x, y, z); script = g.GetComponent <Grid_Unit_Script>(); selectedGridUnit.x = script.x; selectedGridUnit.y = script.y; selectedGridUnit.z = script.z; script.selection.SetActive(true); } if (unselect == true) { script.selection.SetActive(false); } print("The enemy has selected a space"); }