Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by BIO_K · Mar 14, 2017 at 07:04 AM · raycasterror message

Error CS165 after Update

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<Vector3[]> glBuildings = new List<Vector3[]>();
 
         
 void Start () 
 {
     temp = this;
     currentScrollSpeed = scrollSpeed;
     terrain = GameObject.Find ("level").GetComponent<Terrain>();
     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<building>().Sell ();
                 }                    
             }
             else
             {
                 supportValid = false;
             }
         }
         else if (supSel == 2)
         {
             if (hit.collider.tag == "fBuilding" && hit.collider.gameObject.GetComponent<building>().getHealthRatio () < 1)
             {
                 supportValid = true;
                 
                 if (Input.GetMouseButtonDown (0))
                 {
                     //Perform fix commands here
                     hit.collider.gameObject.GetComponent<building>().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<selected>().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<selected>().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<selected>().isSelected && hit.collider.gameObject.GetComponent<unitManager>().deployable)
                 {                        
                     
                     if (hit.collider.gameObject.GetComponent<unitManager>().deployUnit ())
                     {
                         //objectSelected = false;
                         //tUnitSelected = false;
                     }
                     //selectedManager.temp.deselectAll();            
                     
                 }
                 else
                 {
                     selectedManager.temp.deselectAll();
                     selectedManager.temp.addObject (hit.collider.gameObject);
                     //hit.collider.gameObject.GetComponent<selected>().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<selected>().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<unitManager>().isMagnifixz)
                     {
                         g.GetComponent<airMovement>().setTarget (hit.collider.gameObject, true);
                     }
                     else
                     {
                         //g.GetComponent<movement>().setTarget (hit.point);
                         g.GetComponent<unitManager>().attack (hit.collider.gameObject, false);
                     }    
                     
                     //Reset selected timer so path shows up
                     g.GetComponent<selected>().resetJustBeenSelected ();
                 }
             }                
         }
         else if (hit.collider.tag == "fBuilding")
         {
             //Left clicked on a friendly building
             if (Input.GetMouseButtonDown(0) && hit.collider.gameObject.GetComponent<building>().beingPlaced ())
             {
                 //hit.collider.gameObject.GetComponent<building>().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<building>() != null)
             {
                 //Get building ID
                 int tempID = hit.collider.gameObject.GetComponent<building>().ID;
                 //Only certain buildings can interact with certain units
                 
                 //Refinery#
                 if (tempID == 3)
                 {
                     foreach (GameObject g in selectedManager.temp.objects)
                     {
                         if (g.GetComponent<unitManager>().isCollector)
                         {
                             g.GetComponent<ore_unit2>().goToSmelter (hit.collider.gameObject.GetComponent<smelterScript>());
                             
                             //Reset selected timer so path shows up
                             g.GetComponent<selected>().resetJustBeenSelected ();
                         }
                         //g.GetComponent<movement>().setTarget (hit.point);
                         //g.GetComponent<unitManager>().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<unitManager>().isMagnifixz)
                     {
                         g.GetComponent<airMovement>().setTarget (hit.collider.gameObject, true);
                     }
                     //else if (g.tag == "Player" && g.GetComponent<unitManager>().isEngineer)
                     //{
                         //interactSelected = true;
                     //}
                     else if (g.tag == "Player")
                     {
                         //g.GetComponent<movement>().setTarget (hit.point);
                         g.GetComponent<unitManager>().attack (hit.collider.gameObject, true);
                     }
                     //Reset selected timer so path shows up
                     g.GetComponent<selected>().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<float[]> distToTarget = new List<float[]>();
                 //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<unitManager>().isMagnifixz)
                     {
                         g.GetComponent<airMovement>().setTarget (hit.point, false);
                     }
                     else if (g.GetComponent<unitManager>().isCollector)
                     {
                         g.GetComponent<ore_unit2>().setTarget (hit.point);
                     }
                     else
                     {
                         if (moreThan8)
                         {
                             //selectedManager.temp.objects[orderToMove[orderCount
                             //foreach (float[] order in distToTarget)
                             //{
                             selectedManager.temp.objects[(int)distToTarget[sendOrder][0]].GetComponent<movement>().setTarget (hit.point);
                             //}
                             //orderCounter++;
                             sendOrder++;
                         }
                         else
                         {
                             g.GetComponent<movement>().setTarget(hit.point);
                         }
                         
                                             
                         //If unit was moving to attack, make sure it no longer is
                         g.GetComponent<unitManager>().stopAttack ();
                         
                         //if unit was deploying, stop it
                         g.GetComponent<unitManager>().stopDeploy ();                            
                     }
                     //Reset selected timer so path shows up
                     g.GetComponent<selected>().resetJustBeenSelected ();
                 }
             }                        
         }
     }
     
     if (tUnitSelected)
     {
         if (selectedManager.temp.objects.Count == 0) tUnitSelected = false;
     }
     
     interactSelected = false;
     foreach (GameObject g in selectedManager.temp.objects)
     {
         if (g.GetComponent<unitManager>().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<unitManager>().deployable && hit.collider.gameObject.GetComponent<selected>().isSelected && hit.collider.gameObject.GetComponent<unitManager>().canUnitDeploy ())
             {
                 gui.temp.setCursorState ("deploy");
             }
             else if (hit.collider.gameObject.GetComponent<unitManager>().deployable && hit.collider.gameObject.GetComponent<selected>().isSelected)
             {
                 gui.temp.setCursorState ("invalidDeploy");
             }
             else if (hit.collider.gameObject.GetComponent<selected>().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<selected>().isSelected = true;
     objectSelected = true;
     tUnitSelected = true;
 }
 
 public void unitDeselected(GameObject g)
 {
     selectedManager.temp.objects.Remove (g);
     g.GetComponent<selected>().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<selected>().justBeenSelected && g.GetComponent<unitManager>().isMoving ())
         {    
             Vector3 startPos;
             startPos = this.GetComponent<Camera>().WorldToScreenPoint (g.transform.position);
             startPos.z = 0;
             Vector3 endPos;
             GL.PushMatrix ();            
             GL.LoadPixelMatrix();
             mat.SetPass (0);                
             GL.Begin(GL.LINES);
             
             if (g.GetComponent<unitManager>().isMagnifixz)
             {
                 if (g.GetComponent<airMovement>().isAttacking ())
                 {
                     GL.Color (Color.red);
                     endPos = this.GetComponent<Camera>().WorldToScreenPoint (g.GetComponent<airMovement>().getTarget());
                     endPos.z = 0;
                 }
                 else
                 {
                     GL.Color (Color.green);
                     endPos = this.GetComponent<Camera>().WorldToScreenPoint (g.GetComponent<airMovement>().getTarget ());
                     endPos.z = 0;
                 }                    
             }
             else if (g.GetComponent<unitManager>().isAttacking ())
             {
                 GL.Color (Color.red);
                 try
                 {
                     endPos = this.GetComponent<Camera>().WorldToScreenPoint (g.GetComponent<unitManager>().getUnitToAttack ().transform.position);
                     endPos.z = 0;
                 }
                 catch
                 {
                     endPos = startPos;
                 }
             }
             else
             {
                 GL.Color (Color.green);                    
                 endPos = this.GetComponent<Camera>().WorldToScreenPoint (g.GetComponent<movement>().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;
 }

}

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
â–¼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Nehrk · Mar 14, 2017 at 07:51 AM 0
Share

Did you try do delete library folder after update?

avatar image BIO_K · Mar 14, 2017 at 08:01 AM 0
Share

@Nehrk yes i did nothing happened... this is where i get the error

if (hit.collider && Input.mousePosition.x < Screen.width - gui.temp.main$$anonymous$$enuWidth)

as far as I know the second line is the initializing...

Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit;

avatar image Nehrk BIO_K · Mar 14, 2017 at 08:23 AM 0
Share

i see if (supSel != 0 && Physics.Raycast(ray, out hit)) at 214 ln and else if (Input.mousePosition.x < Screen.width - gui.temp.main$$anonymous$$enuWidth && Physics.Raycast(ray, out hit, $$anonymous$$athf.Infinity, ~(1 << 17)) && enable$$anonymous$$ouseClicks) at 251 but i see no else after it. $$anonymous$$aybe this is where the problem hides?

try to debug.Log all if/else constructions and use bool values to check them like

     bool val1 = Input.mousePosition.x < Screen.width - gui.temp.main$$anonymous$$enuWidth;
     bool val2 = Physics.Raycast(ray, out hit, $$anonymous$$athf.Infinity, ~(1 << 17)) && enable$$anonymous$$ouseClicks;
     Debug.Log(val1 +  " screenPos, " + val2 + " - raycast result" );
     else if (Input.mousePosition.x < Screen.width - gui.temp.main$$anonymous$$enuWidth && Physics.Raycast(ray, out hit, $$anonymous$$athf.Infinity, ~(1 << 17)) && enable$$anonymous$$ouseClicks)
 {
 ...
 }

and move forward, just check where is "hit == null"

avatar image BIO_K Nehrk · Mar 14, 2017 at 09:16 AM 0
Share

It seems like everytime I update, I get a setback... Unity is horribly inconsistent with their Language!!!

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by BIO_K · Mar 14, 2017 at 08:44 AM

i was thnking hit = supsel 0... This obviously does not work... I need to assign it some variable...

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
â–¼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

95 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Help with raycast!! 0 Answers

Variable changing from other script does not work. 1 Answer

Getting rid of error message Raycast? 0 Answers

l have been having this on my script error CS8025: Parsing, l don't what to do 1 Answer

It says it's expecting an identifier, and that public is a keyword, but I don't know why! 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges