Quantcast
Channel: Questions in topic: "error message"
Viewing all articles
Browse latest Browse all 2891

Error CS165 after Update

$
0
0
Assets/Scripts/Camera/mainCamera.cs(536,7): error CS0165: Use of unassigned local variable `hit' Here is the script using UnityEngine; using System.Collections; using System.Collections.Generic; public class mainCamera : MonoBehaviour { public float heightAboveGround = 10.0f; public float scrollSpeed = 3.0f; private float currentScrollSpeed; public float angleOffset = 10.0f; private Terrain terrain; private Vector3 terrainCenter; private bool tracking = false; public static mainCamera temp; private bool move = true; private bool objectSelected = false; private bool tUnitSelected = false; private bool interactSelected = false; private bool supportValid = false; public float zOffset = new float(); public float[] mapBounds = new float[4]; public float zoomRate = 0.4f; public bool enableMouseClicks = true; public Vector3[] miniMapCoords; public GameObject startPoint; private float unitScreenSize = 10; private float xMin, xMax, yMin, yMax, cxMin, cxMax, cyMin, cyMax; private Material mat; public List glBuildings = new List(); void Start () { temp = this; currentScrollSpeed = scrollSpeed; terrain = GameObject.Find ("level").GetComponent(); terrainCenter = terrain.terrainData.size/2; transform.position = new Vector3(terrain.terrainData.size.x/2, heightAboveGround, terrain.terrainData.size.z/2); //transform.LookAt (new Vector3((terrain.terrainData.size.x/2)+angleOffset, 0, (terrain.terrainData.size.z/2)+angleOffset)); transform.LookAt (new Vector3((terrain.terrainData.size.x/2), 0, (terrain.terrainData.size.z/2)+angleOffset)); if (startPoint != null) transform.position = new Vector3(startPoint.transform.position.x, heightAboveGround, startPoint.transform.position.z-angleOffset); Ray ray2 = Camera.main.ScreenPointToRay(new Vector3(Screen.width/2, Screen.height/2,0)); RaycastHit hit2; if (Physics.Raycast (ray2, out hit2)) { Vector3 t1 = Camera.main.WorldToScreenPoint(hit2.point+new Vector3(grid.mGrid.getGridSize()/2,0,0)); Vector3 t2 = Camera.main.WorldToScreenPoint(hit2.point-new Vector3(grid.mGrid.getGridSize()/2,0,0)); unitScreenSize = t1.x-t2.x; gui.temp.setUnitSize (unitScreenSize); } createShader (); //mat = new Material("whiteMat"); //mat.color = Color.white; } void Update () { //Camera Movement tracking = false; if (Camera.main.orthographic) { //Find camera viewport Rect cameraRect = miniMapController.temp.getCameraScreen(); if (Input.mousePosition.x == 0 && cameraRect.xMin > mapBounds[0] && move) { transform.Translate (new Vector3(-currentScrollSpeed * Time.deltaTime, 0, 0), Space.World); tracking = true; } else if (Input.mousePosition.x == Screen.width-1 && cameraRect.xMax < mapBounds[1] && move) { transform.Translate(new Vector3(currentScrollSpeed*Time.deltaTime, 0, 0), Space.World); tracking = true; } if (Input.mousePosition.y == 0 && (Screen.height-cameraRect.yMax) > mapBounds[3] && move) { transform.Translate(new Vector3(0, 0, -currentScrollSpeed*Time.deltaTime),Space.World); tracking = true; } else if (Input.mousePosition.y == Screen.height-1 && (Screen.height-cameraRect.yMin) < mapBounds[2] && move) { transform.Translate(new Vector3(0, 0, currentScrollSpeed*Time.deltaTime),Space.World); tracking = true; } } else { //Camera is perspective, find most extreme points Ray mRay = Camera.main.ScreenPointToRay(new Vector3(0, Screen.height, 0)); Ray mRay2 = Camera.main.ScreenPointToRay(new Vector3(Screen.width-gui.temp.mainMenuWidth, Screen.height, 0)); Ray mRay3 = Camera.main.ScreenPointToRay (new Vector3(Screen.width/2, 0, 0)); RaycastHit mHit; if (Physics.Raycast (mRay, out mHit)) { cxMin = mHit.point.x; cyMax = mHit.point.z; } if (Physics.Raycast (mRay2, out mHit)) { cxMax = mHit.point.x; } if (Physics.Raycast (mRay3, out mHit)) { cyMin = mHit.point.z; } if (Input.mousePosition.x == 0 && cxMin > xMin && move) { transform.Translate (new Vector3(-currentScrollSpeed * Time.deltaTime, 0, 0), Space.World); tracking = true; } else if (Input.mousePosition.x == Screen.width-1 && cxMax < xMax && move) { transform.Translate(new Vector3(currentScrollSpeed*Time.deltaTime, 0, 0), Space.World); tracking = true; } if (Input.mousePosition.y == 0 && cyMin > yMin && move) { transform.Translate(new Vector3(0, 0, -currentScrollSpeed*Time.deltaTime),Space.World); tracking = true; } else if (Input.mousePosition.y == Screen.height-1 && cyMax < yMax && move) { transform.Translate(new Vector3(0, 0, currentScrollSpeed*Time.deltaTime),Space.World); tracking = true; } } //Increase Scroll speed the longer the player is moving if (tracking) { if (currentScrollSpeed <= 20) { currentScrollSpeed *= 1.01f; } checkCameraPos (); } else { currentScrollSpeed = scrollSpeed; } //Zoom in/out if (Input.GetAxis ("Mouse ScrollWheel") != 0) { //Zoom In if (Input.GetAxis ("Mouse ScrollWheel") > 0) { if (Camera.main.orthographic) { if (Camera.main.orthographicSize >= 10) Camera.main.orthographicSize -= zoomRate; miniMapController.temp.updateCameraSize(); } else { if (Camera.main.fieldOfView >= 10) Camera.main.fieldOfView -= zoomRate; } } //Zoom out else { if (Camera.main.orthographic) { if (Camera.main.orthographicSize <= 30) Camera.main.orthographicSize += zoomRate*2; miniMapController.temp.updateCameraSize(); } else { if (Camera.main.fieldOfView <= 50) Camera.main.fieldOfView += zoomRate*2; } } //Do some re-sizing calculations Ray ray2 = Camera.main.ScreenPointToRay(new Vector3(Screen.width/2, Screen.height/2,0)); RaycastHit hit2; //tile tempTile; if (Physics.Raycast (ray2, out hit2)) { Vector3 t1 = Camera.main.WorldToScreenPoint(hit2.point+new Vector3(grid.mGrid.getGridSize()/2,0,0)); Vector3 t2 = Camera.main.WorldToScreenPoint(hit2.point-new Vector3(grid.mGrid.getGridSize()/2,0,0)); unitScreenSize = t1.x-t2.x; gui.temp.setUnitSize (unitScreenSize); } checkCameraPos (); } //Raycasting stuff Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; //Handles all in game button clicks that are not GUI related //Is sell or fix selected? int supSel = gui.temp.getSupportSelected(); if (supSel != 0 && Physics.Raycast (ray, out hit)) { if (supSel == 1) { if (hit.collider.tag == "fBuilding") { supportValid = true; if (Input.GetMouseButtonDown (0)) { //Perform sell commands here hit.collider.gameObject.GetComponent().Sell (); } } else { supportValid = false; } } else if (supSel == 2) { if (hit.collider.tag == "fBuilding" && hit.collider.gameObject.GetComponent().getHealthRatio () < 1) { supportValid = true; if (Input.GetMouseButtonDown (0)) { //Perform fix commands here hit.collider.gameObject.GetComponent().Fix (); } } else { supportValid = false; } } } else if (Input.mousePosition.x < Screen.width - gui.temp.mainMenuWidth && Physics.Raycast (ray, out hit, Mathf.Infinity, ~(1 << 17)) && enableMouseClicks) { //Check to see if unit collider lies within building collider if (hit.collider.tag == "fBuilding") { RaycastHit hit2; if (Physics.Raycast (ray, out hit2, Mathf.Infinity, 1 << 8)) { hit = hit2; } } if (hit.collider.tag == "Player") { //Left clicked on player unit while holding shift (select multiple units) if (Input.GetMouseButtonDown(0) && Input.GetKey (KeyCode.LeftShift)) { if (!hit.collider.gameObject.GetComponent().isSelected) { if (selectedManager.temp.objects.Count > 0 && selectedManager.temp.objects[0].tag == "npc") { selectedManager.temp.deselect(); } selectedManager.temp.addObject (hit.collider.gameObject); //hit.collider.gameObject.GetComponent().isSelected = true; objectSelected = true; tUnitSelected = true; } else { unitDeselected(hit.collider.gameObject); } } //Left clicked on player unit else if (Input.GetMouseButtonDown(0)) { //Left clicked on a unit which is selected, depending on the unit perform special actions here if (hit.collider.gameObject.GetComponent().isSelected && hit.collider.gameObject.GetComponent().deployable) { if (hit.collider.gameObject.GetComponent().deployUnit ()) { //objectSelected = false; //tUnitSelected = false; } //selectedManager.temp.deselectAll(); } else { selectedManager.temp.deselectAll(); selectedManager.temp.addObject (hit.collider.gameObject); //hit.collider.gameObject.GetComponent().isSelected = true; objectSelected = true; tUnitSelected = true; } } } else if (hit.collider.tag == "npc") { //Left clicked on non-playable character if (Input.GetMouseButtonDown(0)) { selectedManager.temp.deselectAll(); selectedManager.temp.objects.Add (hit.collider.gameObject); hit.collider.gameObject.GetComponent().isSelected = true; objectSelected = true; } //Right clicked on enemy unit --> Attack! if (Input.GetMouseButtonDown (1) && hit.collider.gameObject.layer == 9) { foreach (GameObject g in selectedManager.temp.objects) { if (g.GetComponent().isMagnifixz) { g.GetComponent().setTarget (hit.collider.gameObject, true); } else { //g.GetComponent().setTarget (hit.point); g.GetComponent().attack (hit.collider.gameObject, false); } //Reset selected timer so path shows up g.GetComponent().resetJustBeenSelected (); } } } else if (hit.collider.tag == "fBuilding") { //Left clicked on a friendly building if (Input.GetMouseButtonDown(0) && hit.collider.gameObject.GetComponent().beingPlaced ()) { //hit.collider.gameObject.GetComponent().justBeenPlaced = false; } else if (Input.GetMouseButtonDown(0) && Input.GetKey (KeyCode.LeftShift)) { selectedManager.temp.addBuilding (hit.collider.gameObject); } else if (Input.GetMouseButtonDown(0)) { selectedManager.temp.deselectAll(); selectedManager.temp.addBuilding (hit.collider.gameObject); } //Right clicked on a friendly building and we have a unit selected if (Input.GetMouseButtonDown (1) && objectSelected && hit.collider.gameObject.GetComponent() != null) { //Get building ID int tempID = hit.collider.gameObject.GetComponent().ID; //Only certain buildings can interact with certain units //Refinery# if (tempID == 3) { foreach (GameObject g in selectedManager.temp.objects) { if (g.GetComponent().isCollector) { g.GetComponent().goToSmelter (hit.collider.gameObject.GetComponent()); //Reset selected timer so path shows up g.GetComponent().resetJustBeenSelected (); } //g.GetComponent().setTarget (hit.point); //g.GetComponent().attack (hit.collider.gameObject); } } } } else if (hit.collider.tag == "eBuilding") { //Left Clicked on enemy building if (Input.GetMouseButtonDown(0) && Input.GetKey (KeyCode.LeftShift)) { selectedManager.temp.addBuilding (hit.collider.gameObject); tUnitSelected = false; } else if (Input.GetMouseButtonDown(0)) { selectedManager.temp.deselectAll(); selectedManager.temp.addBuilding (hit.collider.gameObject); tUnitSelected = false; } //Right clicked on enemy building if (Input.GetMouseButtonDown(1)) { foreach (GameObject g in selectedManager.temp.objects) { if (g.tag == "Player" && g.GetComponent().isMagnifixz) { g.GetComponent().setTarget (hit.collider.gameObject, true); } //else if (g.tag == "Player" && g.GetComponent().isEngineer) //{ //interactSelected = true; //} else if (g.tag == "Player") { //g.GetComponent().setTarget (hit.point); g.GetComponent().attack (hit.collider.gameObject, true); } //Reset selected timer so path shows up g.GetComponent().resetJustBeenSelected (); } } } else { //Left clicked on ground, de-select everything as long as shift isn't been held down if (Input.GetMouseButtonDown(0) && !Input.GetKey (KeyCode.LeftShift)) { selectedManager.temp.deselectAll(); objectSelected = false; tUnitSelected = false; } //Right clicked on ground with object(s) selected, move to point if (Input.GetMouseButtonDown (1) && objectSelected && selectedManager.temp.objects[0].tag == "Player") //if (Input.GetMouseButtonDown (1) && objectSelected) { //Vector3 targetPoint= grid.mGrid.findClosestAvailableTile (hit.point, grid.mGrid.returnClosestTile (hit.point).navMesh).center; bool moreThan8 = false; int[,] orderToMove; int orderCounter = 0; List distToTarget = new List(); //if more than 8 objects selected, need to do send closest units to center if (selectedManager.temp.objects.Count > 8) { moreThan8 = true; orderToMove = new int[selectedManager.temp.objects.Count, 2]; foreach (GameObject g in selectedManager.temp.objects) { int difOrderCounter = -1; float dist = Vector3.Distance (g.transform.position, hit.point); do { difOrderCounter++; if (distToTarget.Count == 0 || distToTarget.Count == difOrderCounter) { distToTarget.Add (new float[2] {orderCounter,dist}); } else { if (dist < distToTarget[difOrderCounter][1]) { distToTarget.Insert (difOrderCounter, new float[2] {orderCounter, dist}); } } } while (dist> distToTarget[difOrderCounter][1]); //distToTarget.Add (new float[] {selectedManager.temp.objects.IndexOf (g),Vector3.Distance (g.transform.position, hit.point)}); orderCounter++; } } int sendOrder=0; foreach (GameObject g in selectedManager.temp.objects) { if (g.GetComponent().isMagnifixz) { g.GetComponent().setTarget (hit.point, false); } else if (g.GetComponent().isCollector) { g.GetComponent().setTarget (hit.point); } else { if (moreThan8) { //selectedManager.temp.objects[orderToMove[orderCount //foreach (float[] order in distToTarget) //{ selectedManager.temp.objects[(int)distToTarget[sendOrder][0]].GetComponent().setTarget (hit.point); //} //orderCounter++; sendOrder++; } else { g.GetComponent().setTarget(hit.point); } //If unit was moving to attack, make sure it no longer is g.GetComponent().stopAttack (); //if unit was deploying, stop it g.GetComponent().stopDeploy (); } //Reset selected timer so path shows up g.GetComponent().resetJustBeenSelected (); } } } } if (tUnitSelected) { if (selectedManager.temp.objects.Count == 0) tUnitSelected = false; } interactSelected = false; foreach (GameObject g in selectedManager.temp.objects) { if (g.GetComponent().isWielder) { interactSelected = true; } } //Handle cursor images if (hit.collider && Input.mousePosition.x < Screen.width - gui.temp.mainMenuWidth) { if (supSel != 0) { if (supSel == 1) { if (supportValid) { gui.temp.setCursorState ("sell"); } else { gui.temp.setCursorState ("sellInvalid"); } } else if (supSel == 2) { if (supportValid) { gui.temp.setCursorState ("fix"); } else { gui.temp.setCursorState ("fixInvalid"); } } } else if (hit.collider.tag == "Player") { if (hit.collider.gameObject.GetComponent().deployable && hit.collider.gameObject.GetComponent().isSelected && hit.collider.gameObject.GetComponent().canUnitDeploy ()) { gui.temp.setCursorState ("deploy"); } else if (hit.collider.gameObject.GetComponent().deployable && hit.collider.gameObject.GetComponent().isSelected) { gui.temp.setCursorState ("invalidDeploy"); } else if (hit.collider.gameObject.GetComponent().isSelected) { gui.temp.setCursorState ("go"); } else { gui.temp.setCursorState ("hover"); } } else if (hit.collider.tag == "fBuilding") { gui.temp.setCursorState ("hover"); } else if (hit.collider.tag == "npc" || hit.collider.tag == "eBuilding") { if (tUnitSelected) { if (interactSelected && hit.collider.tag == "eBuilding") { gui.temp.setCursorState ("bInt"); } else if (interactSelected) { gui.temp.setCursorState ("hover"); } else { gui.temp.setCursorState ("attack"); } } else { gui.temp.setCursorState ("hover"); } } else { if (tUnitSelected) { gui.temp.setCursorState ("go"); } else { gui.temp.setCursorState ("normal"); } } } else { gui.temp.setCursorState ("normal"); } } public void edgeMovement(bool b) { move = b; } public void unitSelected(GameObject g) { selectedManager.temp.objects.Add (g); g.GetComponent().isSelected = true; objectSelected = true; tUnitSelected = true; } public void unitDeselected(GameObject g) { selectedManager.temp.objects.Remove (g); g.GetComponent().isSelected = false; if (selectedManager.temp.objects.Count == 0) { objectSelected = false; tUnitSelected = false; } } public float getScreenUnitSize() { return unitScreenSize; } public void setMaxValues(float xMin, float xMax, float yMin, float yMax) { this.xMin = xMin; this.xMax = xMax; this.yMin = yMin; this.yMax = yMax; } public void checkCameraPos() { Ray r1 = Camera.main.ViewportPointToRay (new Vector3(0,1,0)); Ray r2 = Camera.main.ScreenPointToRay (new Vector3(Screen.width-gui.temp.mainMenuWidth,Screen.height-1,0)); Ray r3 = Camera.main.ViewportPointToRay (new Vector3(0,0,0)); float left, right, top, bottom; RaycastHit h1; Physics.Raycast (r1, out h1, Mathf.Infinity, 1<< 16); left = h1.point.x; top = h1.point.z; Physics.Raycast (r2, out h1, Mathf.Infinity, 1<< 16); right = h1.point.x; Physics.Raycast (r3, out h1, Mathf.Infinity, 1<< 16); bottom = h1.point.z; if (left < xMin) { Camera.main.transform.Translate (new Vector3(xMin-left,0,0), Space.World); } else if (right > xMax) { Camera.main.transform.Translate (new Vector3(xMax-right,0,0), Space.World); } if (bottom < yMin) { Camera.main.transform.Translate (new Vector3(0,0,yMin-bottom), Space.World); } else if (top > yMax) { Camera.main.transform.Translate (new Vector3(0,0,yMax-top), Space.World); } } void OnPostRender() { foreach (Vector3[] v in glBuildings) { //createShader (); //Do some calculations, we need 8 screen co-ordinates //Find world positions of vectors Vector3 worldFBL = new Vector3(v[0].x-(v[1].x/2),v[0].y-(v[1].y/2),v[0].z-(v[1].z/2)); Vector3 worldFTL = new Vector3(v[0].x-(v[1].x/2),v[0].y+(v[1].y/2),v[0].z-(v[1].z/2)); Vector3 worldFTR = new Vector3(v[0].x+(v[1].x/2),v[0].y+(v[1].y/2),v[0].z-(v[1].z/2)); Vector3 worldFBR = new Vector3(v[0].x+(v[1].x/2),v[0].y-(v[1].y/2),v[0].z-(v[1].z/2)); Vector3 forwardBL = Camera.main.WorldToScreenPoint (worldFBL); Vector3 forwardTL = Camera.main.WorldToScreenPoint (worldFTL); Vector3 forwardTR = Camera.main.WorldToScreenPoint (worldFTR); Vector3 forwardBR = Camera.main.WorldToScreenPoint (worldFBR); Vector3 worldBBL = new Vector3(v[0].x-(v[1].x/2),v[0].y-(v[1].y/2),v[0].z+(v[1].z/2)); Vector3 worldBTL = new Vector3(v[0].x-(v[1].x/2),v[0].y+(v[1].y/2),v[0].z+(v[1].z/2)); Vector3 worldBTR = new Vector3(v[0].x+(v[1].x/2),v[0].y+(v[1].y/2),v[0].z+(v[1].z/2)); Vector3 worldBBR = new Vector3(v[0].x+(v[1].x/2),v[0].y-(v[1].y/2),v[0].z+(v[1].z/2)); Vector3 backBL = Camera.main.WorldToScreenPoint (worldBBL); Vector3 backTL = Camera.main.WorldToScreenPoint (worldBTL); Vector3 backTR = Camera.main.WorldToScreenPoint (worldBTR); Vector3 backBR = Camera.main.WorldToScreenPoint (worldBBR); forwardBL.z = 0; forwardTL.z = 0; forwardTR.z = 0; forwardBR.z = 0; backBL.z = 0; backTL.z = 0; backTR.z = 0; backBR.z = 0; float buildingWidth = v[1].x; float healthRatio = v[2].x; float numBoxes = v[2].y; //float boxWidth = buildingWidth/numBoxes; float boxWidth = 0.7f; Vector3 worldCenter = worldBTL + new Vector3(boxWidth/2, -boxWidth/2, -boxWidth/2); GL.PushMatrix (); GL.LoadPixelMatrix(); //mat.color = new Color(1,1,1,1); mat.SetPass (0); GL.Begin (GL.QUADS); float leftX1 = worldBTL.x; float leftX2 = worldBTL.x + (buildingWidth*healthRatio); float leftY1 = worldBTL.y; float leftY2 = worldBTL.y - boxWidth; float leftZ1 = worldBTL.z; float leftZ2 = worldBTL.z - boxWidth; Vector3 leftV1 = Camera.main.WorldToScreenPoint (new Vector3(leftX1, leftY1, leftZ1)); Vector3 leftV2 = Camera.main.WorldToScreenPoint (new Vector3(leftX1, leftY2, leftZ1)); Vector3 leftV3 = Camera.main.WorldToScreenPoint (new Vector3(leftX1, leftY2, leftZ2)); Vector3 leftV4 = Camera.main.WorldToScreenPoint (new Vector3(leftX1, leftY1, leftZ2)); Vector3 rightV1 = Camera.main.WorldToScreenPoint (new Vector3(leftX2, leftY1, leftZ1)); Vector3 rightV2 = Camera.main.WorldToScreenPoint (new Vector3(leftX2, leftY2, leftZ1)); Vector3 rightV3 = Camera.main.WorldToScreenPoint (new Vector3(leftX2, leftY2, leftZ2)); Vector3 rightV4 = Camera.main.WorldToScreenPoint (new Vector3(leftX2, leftY1, leftZ2)); leftV1.z = 0; leftV2.z = 0; leftV3.z = 0; leftV4.z = 0; rightV1.z = 0; rightV2.z = 0; rightV3.z = 0; rightV4.z = 0; if (healthRatio >0.5f) { GL.Color (Color.Lerp (new Color(0,1,0,1), new Color(1,0.84f,0,1), 1-((healthRatio-0.5f)*2))); } else { GL.Color (Color.Lerp (new Color(1,0.84f,0,1), new Color(1,0,0,1), 1-(healthRatio*2))); } //GL.Color (Color.Lerp (new Color(0,1,0,1), new Color(1,0,0,1), 1-healthRatio)); GL.Vertex (leftV1); GL.Vertex (leftV2); GL.Vertex (leftV3); GL.Vertex (leftV4); GL.Color (Color.Lerp (new Color(0,0.7f,0,1), new Color(0.7f,0,0,1), 1-healthRatio)); GL.Vertex (rightV1); GL.Vertex (rightV2); GL.Vertex (rightV3); GL.Vertex (rightV4); if (healthRatio >0.5f) { GL.Color (Color.Lerp (new Color(0,1,0,1), new Color(1,0.84f,0,1), 1-((healthRatio-0.5f)*2))); } else { GL.Color (Color.Lerp (new Color(1,0.84f,0,1), new Color(1,0,0,1), 1-(healthRatio*2))); } GL.Vertex (leftV1); GL.Vertex (leftV4); GL.Vertex (rightV4); GL.Vertex (rightV1); GL.Color (Color.Lerp (new Color(0,0.7f,0,1), new Color(0.7f,0,0,1), 1-healthRatio)); GL.Vertex (leftV4); GL.Vertex (leftV3); GL.Vertex (rightV3); GL.Vertex (rightV4); GL.End (); GL.Begin(GL.LINES); GL.Color (Color.white); GL.Vertex (forwardBL);GL.Vertex (forwardTL); GL.Vertex (forwardTL);GL.Vertex (forwardTR); GL.Vertex (forwardTR);GL.Vertex (forwardBR); GL.Vertex (forwardBR);GL.Vertex (forwardBL); GL.Vertex (backBL);GL.Vertex (backTL); GL.Vertex (backTL);GL.Vertex (backTR); GL.Vertex (backTR);GL.Vertex (backBR); GL.Vertex (backBR);GL.Vertex (backBL); GL.Vertex (forwardBL);GL.Vertex (backBL); GL.Vertex (forwardTL);GL.Vertex (backTL); GL.Vertex (forwardTR);GL.Vertex (backTR); GL.Vertex (forwardBR);GL.Vertex (backBR); GL.End (); GL.PopMatrix (); } //Draw movement lines foreach (GameObject g in selectedManager.temp.objects) { //Only draw line if unit has just been selected if (g.GetComponent().justBeenSelected && g.GetComponent().isMoving ()) { Vector3 startPos; startPos = this.GetComponent().WorldToScreenPoint (g.transform.position); startPos.z = 0; Vector3 endPos; GL.PushMatrix (); GL.LoadPixelMatrix(); mat.SetPass (0); GL.Begin(GL.LINES); if (g.GetComponent().isMagnifixz) { if (g.GetComponent().isAttacking ()) { GL.Color (Color.red); endPos = this.GetComponent().WorldToScreenPoint (g.GetComponent().getTarget()); endPos.z = 0; } else { GL.Color (Color.green); endPos = this.GetComponent().WorldToScreenPoint (g.GetComponent().getTarget ()); endPos.z = 0; } } else if (g.GetComponent().isAttacking ()) { GL.Color (Color.red); try { endPos = this.GetComponent().WorldToScreenPoint (g.GetComponent().getUnitToAttack ().transform.position); endPos.z = 0; } catch { endPos = startPos; } } else { GL.Color (Color.green); endPos = this.GetComponent().WorldToScreenPoint (g.GetComponent().getArrivalTile ().center); endPos.z = 0; } GL.Vertex (startPos);GL.Vertex (endPos); GL.End (); //Square at end of movement line GL.Begin(GL.QUADS); GL.Vertex3 (endPos.x-3, endPos.y-3, 0); GL.Vertex3 (endPos.x-3, endPos.y+3, 0); GL.Vertex3 (endPos.x+3, endPos.y+3, 0); GL.Vertex3 (endPos.x+3, endPos.y-3, 0); GL.End (); GL.PopMatrix (); //Debug.Log ("draw line!"); } } } void createShader() { string shaderText = "Shader \"Lines/Colored Blended\" {" + "SubShader { Pass { " + " Blend SrcAlpha OneMinusSrcAlpha " + " ZWrite Off Cull Off Fog { Mode Off } " + " BindChannels {" + " Bind \"vertex\", vertex Bind \"color\", color }" + "} } }" ; mat = new Material(shaderText); } public void groupObjects(bool b) { objectSelected = b; tUnitSelected = b; } }

Viewing all articles
Browse latest Browse all 2891

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>