void DisplayGhost() { canPlace = false; RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit)) { if (hit.collider != null && terrain.name == terrain.name) { //float steepness = Vector3.Angle(hit.normal, transform.up); // Check build angle float steepness = terrain.terrainData.GetSteepness(hit.point.x / terrain.terrainData.size.x, hit.point.z / terrain.terrainData.size.z); if (steepness <= 30) { // Check restrictionrange LayerMask mask = LayerMask.GetMask("Towers"); Collider[] Turrets = Physics.OverlapSphere(hit.point, restrictionRange, mask); Collider[] TurretBuildDistance = Physics.OverlapSphere(hit.point, maxDistance, mask); //Debug.Log (Turrets.Length + " " + TurretBuildDistance.Length); //Debug.Log ("Turret count is " + turretList.Count); float dis = Vector3.Distance(GameManager._instance.regionManager.goal.transform.position, hit.point); //Debug.Log ("Distance is " + dis); if (Turrets.Length == 0 && (TurretBuildDistance.Length >= 1 || dis < goalDist)) { canPlace = true; } } if (dispGhost) { dispGhost.transform.position = hit.point; dispGhost.transform.rotation = hit.transform.rotation; } else { dispGhost = Instantiate(turretGhost, hit.point, hit.transform.rotation) as GameObject; } } } ghostTurret curr = dispGhost.GetComponent <ghostTurret> (); curr.SetMode(canPlace); }
/* Note for the below functions, may be able to be condensed/optimized. I know * I have a lot going on, but I was cramming the buildmanager script and shop script * I had into this script so let me know if you want edits to this Sam =) */ /* Set the value for turretToBuild to the turret selected from GUI */ public void SelectTurretToBuild(GameObject turret) { turretBtnPressed = (!turretBtnPressed); if (turretBtnPressed) { ghostTurret curr = turret.GetComponent <ghostTurret> (); turretToBuild = curr.turret; turretGhost = turret; } else { Destroy(dispGhost); turretBtnPressed = false; if (turret.name != turretGhost.name) { SelectTurretToBuild(turret); } } }