Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Script help!

Discussion in 'Scripting' started by gringofxs, Feb 12, 2016.

  1. gringofxs

    gringofxs

    Joined:
    Oct 14, 2012
    Posts:
    240
    Unity show an error in the console. I need to fix,
    Assets/TestScripts/TestMap.cs(161,9): error CS0161: `TestMap.Start()': not all code paths return a value

    heres the code

    Code (CSharp):
    1. //
    2. //  TestMap.cs
    3. //
    4. //  Author:
    5. //       Jonathan Derrough <jonathan.derrough@gmail.com>
    6. //
    7. //  Copyright (c) 2012 Jonathan Derrough
    8. //
    9. //  This program is free software: you can redistribute it and/or modify
    10. //  it under the terms of the GNU Lesser General Public License as published by
    11. //  the Free Software Foundation, either version 3 of the License, or
    12. //  (at your option) any later version.
    13. //
    14. //  This program is distributed in the hope that it will be useful,
    15. //  but WITHOUT ANY WARRANTY; without even the implied warranty of
    16. //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    17. //  GNU Lesser General Public License for more details.
    18. //
    19. //  You should have received a copy of the GNU Lesser General Public License
    20. //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
    21.  
    22. using UnityEngine;
    23.  
    24. using System;
    25.  
    26. using UnitySlippyMap.Map;
    27. using UnitySlippyMap.Markers;
    28. using UnitySlippyMap.Layers;
    29. using ProjNet.CoordinateSystems;
    30. using ProjNet.CoordinateSystems.Transformations;
    31. using ProjNet.Converters.WellKnownText;
    32. using System.IO;
    33. using System.Collections;
    34. using System.Collections.Generic;
    35.  
    36. public class TestMap : MonoBehaviour
    37. {
    38.     private MapBehaviour        map;
    39.    
    40.     public Texture    LocationTexture;
    41.     public Texture    MarkerTexture;
    42.    
    43.     private float    guiXScale;
    44.     private float    guiYScale;
    45.     private Rect    guiRect;
    46.    
    47.     private bool     isPerspectiveView = false;
    48.     private float    perspectiveAngle = 30.0f;
    49.     private float    destinationAngle = 0.0f;
    50.     private float    currentAngle = 0.0f;
    51.     private float    animationDuration = 0.5f;
    52.     private float    animationStartTime = 0.0f;
    53.  
    54.     private List<LayerBehaviour> layers;
    55.     private int     currentLayerIndex = 0;
    56.    
    57.     bool Toolbar(MapBehaviour map)
    58.     {
    59.         GUI.matrix = Matrix4x4.Scale(new Vector3(guiXScale, guiXScale, 1.0f));
    60.        
    61.         GUILayout.BeginArea(guiRect);
    62.        
    63.         GUILayout.BeginHorizontal();
    64.        
    65.         //GUILayout.Label("Zoom: " + map.CurrentZoom);
    66.        
    67.         bool pressed = false;
    68.         if (GUILayout.RepeatButton("+", GUILayout.ExpandHeight(true)))
    69.         {
    70.             map.Zoom(1.0f);
    71.             pressed = true;
    72.         }
    73.         if (Event.current.type == EventType.Repaint)
    74.         {
    75.             Rect rect = GUILayoutUtility.GetLastRect();
    76.             if (rect.Contains(Event.current.mousePosition))
    77.                 pressed = true;
    78.         }
    79.  
    80.         if (GUILayout.Button("2D/3D", GUILayout.ExpandHeight(true)))
    81.         {
    82.             if (isPerspectiveView)
    83.             {
    84.                 destinationAngle = -perspectiveAngle;
    85.             }
    86.             else
    87.             {
    88.                 destinationAngle = perspectiveAngle;
    89.             }
    90.            
    91.             animationStartTime = Time.time;
    92.            
    93.             isPerspectiveView = !isPerspectiveView;
    94.         }
    95.         if (Event.current.type == EventType.Repaint)
    96.         {
    97.             Rect rect = GUILayoutUtility.GetLastRect();
    98.             if (rect.Contains(Event.current.mousePosition))
    99.                 pressed = true;
    100.         }
    101.  
    102.         if (GUILayout.Button("Center", GUILayout.ExpandHeight(true)))
    103.         {
    104.             map.CenterOnLocation();
    105.         }
    106.         if (Event.current.type == EventType.Repaint)
    107.         {
    108.             Rect rect = GUILayoutUtility.GetLastRect();
    109.             if (rect.Contains(Event.current.mousePosition))
    110.                 pressed = true;
    111.         }
    112.  
    113.         string layerMessage = String.Empty;
    114.         if (map.CurrentZoom > layers[currentLayerIndex].MaxZoom)
    115.             layerMessage = "\nZoom out!";
    116.         else if (map.CurrentZoom < layers[currentLayerIndex].MinZoom)
    117.             layerMessage = "\nZoom in!";
    118.         if (GUILayout.Button(((layers != null && currentLayerIndex < layers.Count) ? layers[currentLayerIndex].name + layerMessage : "Layer"), GUILayout.ExpandHeight(true)))
    119.         {
    120. #if UNITY_3_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5 || UNITY_3_6 || UNITY_3_7 || UNITY_3_8 || UNITY_3_9
    121.             layers[currentLayerIndex].gameObject.SetActiveRecursively(false);
    122. #else
    123.             layers[currentLayerIndex].gameObject.SetActive(false);
    124. #endif
    125.             ++currentLayerIndex;
    126.             if (currentLayerIndex >= layers.Count)
    127.                 currentLayerIndex = 0;
    128. #if UNITY_3_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5 || UNITY_3_6 || UNITY_3_7 || UNITY_3_8 || UNITY_3_9
    129.             layers[currentLayerIndex].gameObject.SetActiveRecursively(true);
    130. #else
    131.             layers[currentLayerIndex].gameObject.SetActive(true);
    132. #endif
    133.             map.IsDirty = true;
    134.         }
    135.  
    136.         if (GUILayout.RepeatButton("-", GUILayout.ExpandHeight(true)))
    137.         {
    138.             map.Zoom(-1.0f);
    139.             pressed = true;
    140.         }
    141.         if (Event.current.type == EventType.Repaint)
    142.         {
    143.             Rect rect = GUILayoutUtility.GetLastRect();
    144.             if (rect.Contains(Event.current.mousePosition))
    145.                 pressed = true;
    146.         }
    147.        
    148.         GUILayout.EndHorizontal();
    149.                    
    150.         GUILayout.EndArea();
    151.        
    152.         return pressed;
    153.     }
    154.    
    155.     private
    156. #if !UNITY_WEBPLAYER
    157.         IEnumerator
    158. #else
    159.         void
    160. #endif
    161.         Start()
    162.     {
    163.         // setup the gui scale according to the screen resolution
    164.         guiXScale = (Screen.orientation == ScreenOrientation.Landscape ? Screen.width : Screen.height) / 480.0f;
    165.         guiYScale = (Screen.orientation == ScreenOrientation.Landscape ? Screen.height : Screen.width) / 640.0f;
    166.         // setup the gui area
    167.         guiRect = new Rect(16.0f * guiXScale, 4.0f * guiXScale, Screen.width / guiXScale - 32.0f * guiXScale, 32.0f * guiYScale);
    168.  
    169.         // create the map singleton
    170.         map = MapBehaviour.Instance;
    171.         map.CurrentCamera = Camera.main;
    172.         map.InputDelegate += UnitySlippyMap.Input.MapInput.BasicTouchAndKeyboard;
    173.         map.CurrentZoom = 15.0f;
    174.         // 9 rue Gentil, Lyon
    175.         map.CenterWGS84 = new double[2] { 4.83527, 45.76487 };
    176.         map.UsesLocation = true;
    177.         map.InputsEnabled = true;
    178.         map.ShowsGUIControls = true;
    179.  
    180.         map.GUIDelegate += Toolbar;
    181.  
    182.         layers = new List<LayerBehaviour>();
    183.  
    184.         // create an OSM tile layer
    185.         OSMTileLayer osmLayer = map.CreateLayer<OSMTileLayer>("OSM");
    186.         osmLayer.BaseURL = "http://a.tile.openstreetmap.org/";
    187.        
    188.         layers.Add(osmLayer);
    189.  
    190.  
    191.  
    192.         // create some test 2D markers
    193.         GameObject go = TileBehaviour.CreateTileTemplate(TileBehaviour.AnchorPoint.BottomCenter).gameObject;
    194.         go.GetComponent<Renderer>().material.mainTexture = MarkerTexture;
    195.         go.GetComponent<Renderer>().material.renderQueue = 4001;
    196.         go.transform.localScale = new Vector3(0.70588235294118f, 1.0f, 1.0f);
    197.         go.transform.localScale /= 7.0f;
    198.         go.AddComponent<CameraFacingBillboard>().Axis = Vector3.up;
    199.        
    200.         GameObject markerGO;
    201.         markerGO = Instantiate(go) as GameObject;
    202.         map.CreateMarker<MarkerBehaviour>("test marker - 9 rue Gentil, Lyon", new double[2] { 4.83527, 45.76487 }, markerGO);
    203.  
    204.         markerGO = Instantiate(go) as GameObject;
    205.         map.CreateMarker<MarkerBehaviour>("test marker - 31 rue de la Bourse, Lyon", new double[2] { 4.83699, 45.76535 }, markerGO);
    206.        
    207.         markerGO = Instantiate(go) as GameObject;
    208.         map.CreateMarker<MarkerBehaviour>("test marker - 1 place St Nizier, Lyon", new double[2] { 4.83295, 45.76468 }, markerGO);
    209.  
    210.         markerGO = Instantiate(go) as GameObject;
    211.         map.CreateMarker<MarkerBehaviour>("R. Itaipu - Res. Colina do Sol", new double[2] {-48.95889645, -21.114459106132305 }, markerGO);
    212.  
    213.         DestroyImmediate(go);
    214.        
    215.         // create the location marker
    216.         go = TileBehaviour.CreateTileTemplate().gameObject;
    217.         go.GetComponent<Renderer>().material.mainTexture = LocationTexture;
    218.         go.GetComponent<Renderer>().material.renderQueue = 4000;
    219.         go.transform.localScale /= 27.0f;
    220.        
    221.         markerGO = Instantiate(go) as GameObject;
    222.         map.SetLocationMarker<LocationMarkerBehaviour>(markerGO);
    223.  
    224.         DestroyImmediate(go);
    225.     }
    226.    
    227.     void OnApplicationQuit()
    228.     {
    229.         map = null;
    230.     }
    231.    
    232.     void Update()
    233.     {
    234.         if (destinationAngle != 0.0f)
    235.         {
    236.             Vector3 cameraLeft = Quaternion.AngleAxis(-90.0f, Camera.main.transform.up) * Camera.main.transform.forward;
    237.             if ((Time.time - animationStartTime) < animationDuration)
    238.             {
    239.                 float angle = Mathf.LerpAngle(0.0f, destinationAngle, (Time.time - animationStartTime) / animationDuration);
    240.                 Camera.main.transform.RotateAround(Vector3.zero, cameraLeft, angle - currentAngle);
    241.                 currentAngle = angle;
    242.             }
    243.             else
    244.             {
    245.                 Camera.main.transform.RotateAround(Vector3.zero, cameraLeft, destinationAngle - currentAngle);
    246.                 destinationAngle = 0.0f;
    247.                 currentAngle = 0.0f;
    248.                 map.IsDirty = true;
    249.             }
    250.            
    251.             map.HasMoved = true;
    252.         }
    253.     }
    254.    
    255. #if DEBUG_PROFILE
    256.     void LateUpdate()
    257.     {
    258.         Debug.Log("PROFILE:\n" + UnitySlippyMap.Profiler.Dump());
    259.         UnitySlippyMap.Profiler.Reset();
    260.     }
    261. #endif
    262. }
    263.  
     
  2. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
  3. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    Code (csharp):
    1.  
    2.   private
    3. #if !UNITY_WEBPLAYER
    4.         IEnumerator
    5. #else
    6.         void
    7. #endif
    8.         Start()
    9. {
    10.  
    and yet start() doesn't contain a yield return, so if it's been set as an ienumerator return type it's not being fulfilled
     
  4. gringofxs

    gringofxs

    Joined:
    Oct 14, 2012
    Posts:
    240
    can u help me fix.