Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Creating a terain editor tool and cannot get ONSceneGUI to run

Discussion in 'Editor & General Support' started by PawPrintProductionsLLC, May 28, 2022.

  1. PawPrintProductionsLLC

    PawPrintProductionsLLC

    Joined:
    Mar 14, 2021
    Posts:
    3
    I will post my code below but I do not see a problem with this, not sure exactly what you would need to see so I will post the whole 500 lines, not sure where else to go to ask for assistance, I have done this successfully before but not as indepth and also it was years ago. so I am not sure where I am going wrong. OnSceneGUI is called towards the bottom, most this code is an editor GUI

    If it is relavant I am attempting to cast a ray to detect a tile then raise it by a desired ammount, if anybody knows a more efficient way of going about doing this feel free to help with any ideas as well while I'm here.
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEditor;
    5.  
    6. public class WorldCreationTool : EditorWindow
    7. {
    8.     //Define menu icons.
    9.     public Texture flat;
    10.  
    11.     public Texture inclineEnabled;
    12.     public Texture inclineDisabled;
    13.  
    14.     public Texture hillEnabled;
    15.     public Texture hillDisabled;
    16.  
    17.     public Texture cliffEnabled;
    18.     public Texture cliffDisabled;
    19.  
    20.     public Texture add;
    21.     public Texture minus;
    22.  
    23.     //Define tile variants.
    24.     public Texture currentIcon;
    25.  
    26.     //Define data
    27.     public TileSets setData;
    28.     public TileSet currentTileSet = new TileSet();
    29.  
    30.     //Define what tool to use.
    31.     public bool flatTool = true;
    32.     public bool inclineTool = false;
    33.     public bool hillTool = false;
    34.     public bool cliffTool = false;
    35.  
    36.     public bool raiseTool = false;
    37.     public bool lowerTool = false;
    38.  
    39.     public int tileVariant = 1;
    40.  
    41.     [MenuItem("Envirnment Tools/World Editor Tool")]
    42.     static void Init()
    43.     {
    44.         // Get existing open window or if none, make a new one:
    45.         WorldCreationTool window = (WorldCreationTool)GetWindow(typeof(WorldCreationTool));
    46.  
    47.         window.maxSize = new Vector2(644f, 780f);
    48.         window.minSize = window.maxSize;
    49.  
    50.         window.Show();
    51.     }
    52.  
    53.     void OnGUI()
    54.     {
    55.         //Define label style//
    56.         var labelStyle = GUI.skin.GetStyle("Label"); //Define label style.
    57.         labelStyle.alignment = TextAnchor.MiddleCenter; //Define label position.
    58.         labelStyle.fontSize = 46; //Define label size.
    59.  
    60.         GUILayout.Label("World Creation Tool", labelStyle, GUILayout.Width(Screen.width), GUILayout.Height(46)); //Main Title
    61.  
    62.         ///////////////////////////////////////////Current Tool///////////////////////////////////////////////////
    63.  
    64.         if (!currentTileSet.defaultTile) //Set the current tile set to the default tile set.
    65.             currentTileSet = setData.defaultSet;
    66.  
    67.         if (!currentIcon) //Set the current icon to the default tile set.
    68.             currentIcon = currentTileSet.defaultIcon;
    69.  
    70.         Texture flatIconCurrent = flat; //Configure the flat icon to use.
    71.  
    72.         Texture inclineIconCurrent = inclineDisabled; //Configure the incline icon to use.
    73.         if (currentTileSet.hasIncline)
    74.             inclineIconCurrent = inclineEnabled;
    75.  
    76.         Texture hillIconCurrent = hillDisabled; //Configure the hill icon to use.
    77.         if (currentTileSet.hasHill)
    78.             hillIconCurrent = hillEnabled;
    79.  
    80.         Texture CliffIconCurrent = cliffDisabled; //Configure the cliff icon to use.
    81.         if (currentTileSet.hasCliff)
    82.             CliffIconCurrent = cliffEnabled;
    83.  
    84.         //Background Properties
    85.         var backgroundStyle = GUI.skin.GetStyle("Box");
    86.  
    87.         //Begin tool box//
    88.         GUILayout.BeginArea(new Rect(8, 52, Screen.width - 16, 170), backgroundStyle);
    89.         GUILayout.BeginHorizontal();
    90.         GUILayout.BeginVertical();
    91.         GUILayout.BeginHorizontal();
    92.  
    93.         labelStyle.fontSize = 18; //Define label size.
    94.         GUILayout.Label(currentTileSet.setName, labelStyle, GUILayout.Width(120), GUILayout.Height(32));
    95.  
    96.         labelStyle.fontSize = 24; //Define label size.
    97.         labelStyle.alignment = TextAnchor.UpperCenter; //Define Label position.
    98.         GUILayout.Label("Current Brush", labelStyle, GUILayout.Width((Screen.width / 2) + 16), GUILayout.Height(32));
    99.  
    100.         GUILayout.EndHorizontal();
    101.  
    102.         //Define current terrain icon.
    103.         GUILayout.Box(currentIcon, GUILayout.Width(120), GUILayout.Height(120));
    104.  
    105.         GUILayout.EndVertical();
    106.         GUILayout.BeginVertical();
    107.  
    108.         labelStyle.alignment = TextAnchor.MiddleLeft; //Define Label position.
    109.         labelStyle.fontSize = 12; //Define label size.
    110.  
    111.         if (flatTool)
    112.         {
    113.             GUILayout.Label("Flat Tool", labelStyle, GUILayout.Width(80), GUILayout.Height(16));
    114.             GUILayout.Box(flatIconCurrent, GUILayout.Width(40), GUILayout.Height(40));
    115.         }
    116.         if (inclineTool)
    117.         {
    118.             GUILayout.Label("Incline Tool", labelStyle, GUILayout.Width(80), GUILayout.Height(16));
    119.             GUILayout.Box(inclineIconCurrent, GUILayout.Width(40), GUILayout.Height(40));
    120.         }
    121.         if (hillTool)
    122.         {
    123.             GUILayout.Label("Hill Tool", labelStyle, GUILayout.Width(80), GUILayout.Height(16));
    124.             GUILayout.Box(hillIconCurrent, GUILayout.Width(40), GUILayout.Height(40));
    125.         }
    126.         if (cliffTool)
    127.         {
    128.             GUILayout.Label("Cliff Tool", labelStyle, GUILayout.Width(80), GUILayout.Height(16));
    129.             GUILayout.Box(CliffIconCurrent, GUILayout.Width(40), GUILayout.Height(40));
    130.         }
    131.  
    132.         //Define if raise or lower tool is in use
    133.         if (raiseTool)
    134.         {
    135.             GUILayout.Label("Raise Tool", labelStyle, GUILayout.Width(80), GUILayout.Height(16));
    136.             GUILayout.Box(add, GUILayout.Width(40), GUILayout.Height(40));
    137.         }
    138.         if (lowerTool)
    139.         {
    140.             GUILayout.Label("Lower Tool", labelStyle, GUILayout.Width(80), GUILayout.Height(16));
    141.             GUILayout.Box(minus, GUILayout.Width(40), GUILayout.Height(40));
    142.         }
    143.  
    144.         GUILayout.EndVertical();
    145.         GUILayout.EndHorizontal();
    146.         GUILayout.EndArea();
    147.         ///////////////////////////////////////////Current Tool///////////////////////////////////////////////////
    148.  
    149.  
    150.         ///////////////////////////////////////////Terrain Tool///////////////////////////////////////////////////
    151.  
    152.         //Background Properties
    153.         GUILayout.BeginArea(new Rect(8, 230, Screen.width - 16, 160), backgroundStyle); //Define container
    154.  
    155.         //Define title properties.
    156.         labelStyle.fontSize = 18; //Define label size.
    157.         GUILayout.Label("Terrain Brushes", labelStyle, GUILayout.Width(Screen.width), GUILayout.Height(32)); //Title
    158.  
    159.         GUILayout.BeginHorizontal();
    160.         GUILayout.BeginVertical();
    161.  
    162.         //Define tile set label properties.
    163.         labelStyle.fontSize = GUI.skin.font.fontSize; //Define label size.
    164.         GUILayout.Label(setData.defaultSet.setName, labelStyle, GUILayout.Width(80), GUILayout.Height(32));
    165.  
    166.         //Define terrain button properties.
    167.         var buttonStyle = GUI.skin.GetStyle("Button");
    168.  
    169.         if (GUILayout.Button(setData.defaultSet.defaultIcon, buttonStyle, GUILayout.Width(80), GUILayout.Height(80))) //Button
    170.         {
    171.             currentTileSet = setData.defaultSet;
    172.             currentIcon = currentTileSet.defaultIcon;
    173.             tileVariant = 1;
    174.         }
    175.         GUILayout.EndVertical();
    176.  
    177.         for (int x = 0; x < 4; x++)
    178.             if (setData.additionalSets.Count >= x)
    179.             {
    180.                 GUILayout.BeginVertical();
    181.                 GUILayout.Label(setData.additionalSets[x].setName, labelStyle, GUILayout.Width(80), GUILayout.Height(32));
    182.                 if (GUILayout.Button(setData.additionalSets[x].defaultIcon, buttonStyle, GUILayout.Width(80), GUILayout.Height(80))) //Button
    183.                 {
    184.                     currentTileSet = setData.additionalSets[x];
    185.                     currentIcon = currentTileSet.defaultIcon;
    186.                     tileVariant = 1;
    187.  
    188.                     //All the default sets that do not have cliffs don't have hills either so this works as of now.
    189.                     //This method may prove troublesome later if made to be modular.
    190.                     if (!setData.additionalSets[x].hasHill)
    191.                     {
    192.                         if (hillTool || cliffTool) {
    193.                             flatTool = true;
    194.                             inclineTool = false;
    195.                             hillTool = false;
    196.                             cliffTool = false;
    197.  
    198.                             raiseTool = false;
    199.                             lowerTool = false;
    200.                         }
    201.                     }
    202.                 }
    203.                 GUILayout.EndVertical();
    204.             }
    205.         GUILayout.EndHorizontal();
    206.         GUILayout.EndArea();
    207.         ///////////////////////////////////////////Terrain Tool///////////////////////////////////////////////////
    208.  
    209.  
    210.         ///////////////////////////////////////////Tile Variant///////////////////////////////////////////////////
    211.  
    212.         backgroundStyle = GUI.skin.GetStyle("Box");
    213.         GUILayout.BeginArea(new Rect(8, 398, Screen.width - 16, 114), backgroundStyle); //Define container
    214.  
    215.         labelStyle.fontSize = 18; //Define label size.
    216.         GUILayout.Label("Tile Variants", labelStyle, GUILayout.Width(Screen.width), GUILayout.Height(32)); //Title
    217.  
    218.         GUILayout.BeginHorizontal();
    219.  
    220.         if (GUILayout.Button(currentTileSet.defaultIcon, buttonStyle, GUILayout.Width(75), GUILayout.Height(75))) //Button
    221.         {
    222.             tileVariant = 1;
    223.             currentIcon = currentTileSet.defaultIcon;
    224.         }
    225.  
    226.         if (currentTileSet.iconTwo)
    227.             if (GUILayout.Button(currentTileSet.iconTwo, buttonStyle, GUILayout.Width(75), GUILayout.Height(75))) //Button
    228.             {
    229.                 tileVariant = 2;
    230.                 currentIcon = currentTileSet.iconTwo;
    231.             }
    232.  
    233.         if (currentTileSet.iconThree)
    234.             if (GUILayout.Button(currentTileSet.iconThree, buttonStyle, GUILayout.Width(75), GUILayout.Height(75))) //Button
    235.             {
    236.                 tileVariant = 3;
    237.                 currentIcon = currentTileSet.iconThree;
    238.             }
    239.  
    240.         if (currentTileSet.iconFour)
    241.             if (GUILayout.Button(currentTileSet.iconFour, buttonStyle, GUILayout.Width(75), GUILayout.Height(75))) //Button
    242.             {
    243.                 tileVariant = 4;
    244.                 currentIcon = currentTileSet.iconFour;
    245.             }
    246.  
    247.         if (currentTileSet.iconFive)
    248.             if (GUILayout.Button(currentTileSet.iconFive, buttonStyle, GUILayout.Width(75), GUILayout.Height(75))) //Button
    249.             {
    250.                 tileVariant = 5;
    251.                 currentIcon = currentTileSet.iconFive;
    252.             }
    253.  
    254.         if (currentTileSet.iconSix)
    255.             if (GUILayout.Button(currentTileSet.iconSix, buttonStyle, GUILayout.Width(75), GUILayout.Height(75))) //Button
    256.             {
    257.                 tileVariant = 6;
    258.                 currentIcon = currentTileSet.iconSix;
    259.             }
    260.  
    261.         if (currentTileSet.iconSeven)
    262.             if (GUILayout.Button(currentTileSet.iconSeven, buttonStyle, GUILayout.Width(75), GUILayout.Height(75))) //Button
    263.             {
    264.                 tileVariant = 7;
    265.                 currentIcon = currentTileSet.iconSeven;
    266.             }
    267.  
    268.         if (currentTileSet.iconEight)
    269.             if (GUILayout.Button(currentTileSet.iconEight, buttonStyle, GUILayout.Width(75), GUILayout.Height(75))) //Button
    270.             {
    271.                 tileVariant = 8;
    272.                 currentIcon = currentTileSet.iconEight;
    273.             }
    274.  
    275.         GUILayout.EndHorizontal();
    276.         GUILayout.EndArea();
    277.  
    278.         ///////////////////////////////////////////Tile Variant///////////////////////////////////////////////////
    279.  
    280.  
    281.         ////////////////////////////////////////////Terrain Tool//////////////////////////////////////////////////
    282.  
    283.         Texture flatIconToUse = flat; //Configure the incline icon to use.
    284.  
    285.         Texture inclineIconToUse = inclineDisabled; //Configure the incline icon to use.
    286.         if (currentTileSet.hasIncline)
    287.             inclineIconToUse = inclineEnabled;
    288.  
    289.         Texture hillIconToUse = hillDisabled; //Configure the hill icon to use.
    290.         if (currentTileSet.hasHill)
    291.             hillIconToUse = hillEnabled;
    292.  
    293.         Texture CliffIconToUse = cliffDisabled; //Configure the cliff icon to use.
    294.         if (currentTileSet.hasCliff)
    295.             CliffIconToUse = cliffEnabled;
    296.  
    297.         GUILayout.BeginArea(new Rect(8, 520, Screen.width - 16, 260), backgroundStyle); //Define container
    298.  
    299.         GUILayout.Label("Terrain Tools", labelStyle, GUILayout.Width(Screen.width), GUILayout.Height(32)); //Title
    300.  
    301.         GUILayout.BeginHorizontal();
    302.  
    303.         //Define the style for the tool labels.
    304.         labelStyle.fontSize = GUI.skin.font.fontSize; //Define label size.
    305.  
    306.         var toolButtons = GUI.skin.GetStyle("Button");
    307.  
    308.         GUILayout.BeginVertical();
    309.  
    310.         GUILayout.Label("Flat", labelStyle, GUILayout.Width(60), GUILayout.Height(32));
    311.  
    312.         if (GUILayout.Button(flatIconToUse, toolButtons, GUILayout.Width(80), GUILayout.Height(80))) //Button
    313.         {
    314.             flatTool = true;
    315.             inclineTool = false;
    316.             hillTool = false;
    317.             cliffTool = false;
    318.  
    319.             raiseTool = false;
    320.             lowerTool = false;
    321.         }
    322.         GUILayout.EndVertical();
    323.  
    324.         if (currentTileSet.hasIncline)
    325.         {
    326.             GUILayout.BeginVertical();
    327.  
    328.             GUILayout.Label("Incline", labelStyle, GUILayout.Width(60), GUILayout.Height(32));
    329.  
    330.             if (GUILayout.Button(inclineIconToUse, toolButtons, GUILayout.Width(80), GUILayout.Height(80))) //Button
    331.             {
    332.                 flatTool = false;
    333.                 inclineTool = true;
    334.                 hillTool = false;
    335.                 cliffTool = false;
    336.  
    337.                 //Cannot use a height altering tool without determining which direction to alter the height.
    338.                 //This method may prove troublesome later if made to be modular.
    339.                 if (!raiseTool && !lowerTool)
    340.                     raiseTool = true;
    341.             }
    342.  
    343.             if (!flatTool)
    344.             {
    345.                 GUILayout.BeginVertical();
    346.                 GUILayout.Label("Raise Tool", labelStyle, GUILayout.Width(90), GUILayout.Height(32));
    347.                 if (GUILayout.Button(add, GUILayout.Width(60), GUILayout.Height(60))) //Blank
    348.                 {
    349.                     raiseTool = true;
    350.                     lowerTool = false;
    351.                 }
    352.                 GUILayout.EndVertical();
    353.             }
    354.             else
    355.             {
    356.                 GUILayout.BeginVertical();
    357.                 GUILayout.Label("Raise Tool", GUILayout.Width(90), GUILayout.Height(32));
    358.                 GUILayout.Box(add, toolButtons, GUILayout.Width(60), GUILayout.Height(60)); //Blank
    359.                 GUILayout.EndVertical();
    360.  
    361.             }
    362.  
    363.             GUILayout.EndVertical();
    364.         }
    365.         else
    366.         {
    367.             GUILayout.BeginVertical();
    368.             GUILayout.Label("Incline", labelStyle, GUILayout.Width(60), GUILayout.Height(32));
    369.             GUILayout.Box(inclineIconToUse, toolButtons, GUILayout.Width(80), GUILayout.Height(80)); //Blank
    370.  
    371.             if (!flatTool)
    372.             {
    373.                 GUILayout.BeginVertical();
    374.                 GUILayout.Label("Raise Tool", labelStyle, GUILayout.Width(90), GUILayout.Height(32));
    375.                 if (GUILayout.Button(add, GUILayout.Width(60), GUILayout.Height(60))) //Blank
    376.                 {
    377.                     raiseTool = true;
    378.                     lowerTool = false;
    379.                 }
    380.                 GUILayout.EndVertical();
    381.             }
    382.             else
    383.             {
    384.                 GUILayout.BeginVertical();
    385.                 GUILayout.Label("Raise Tool", GUILayout.Width(90), GUILayout.Height(32));
    386.                 GUILayout.Box(add, toolButtons, GUILayout.Width(60), GUILayout.Height(60)); //Blank
    387.                 GUILayout.EndVertical();
    388.  
    389.             }
    390.  
    391.             GUILayout.EndVertical();
    392.         }
    393.  
    394.         if (currentTileSet.hasHill)
    395.         {
    396.             GUILayout.BeginVertical();
    397.  
    398.             GUILayout.Label("Hill", labelStyle, GUILayout.Width(60), GUILayout.Height(32));
    399.  
    400.             if (GUILayout.Button(hillIconToUse, toolButtons, GUILayout.Width(80), GUILayout.Height(80))) //Button
    401.             {
    402.                 flatTool = false;
    403.                 inclineTool = false;
    404.                 hillTool = true;
    405.                 cliffTool = false;
    406.  
    407.                 //Cannot use a height altering tool without determining which direction to alter the height.
    408.                 //This method may prove troublesome later if made to be modular.
    409.                 if (!raiseTool && !lowerTool)
    410.                     raiseTool = true;
    411.             }
    412.  
    413.             if (!flatTool)
    414.             {
    415.                 GUILayout.BeginVertical();
    416.                 GUILayout.Label("Lower Tool", labelStyle, GUILayout.Width(90), GUILayout.Height(32));
    417.                 if (GUILayout.Button(minus, GUILayout.Width(60), GUILayout.Height(60))) //Blank
    418.                 {
    419.                     raiseTool = false;
    420.                     lowerTool = true;
    421.                 }
    422.                 GUILayout.EndVertical();
    423.             }
    424.             else
    425.             {
    426.                 GUILayout.BeginVertical();
    427.                 GUILayout.Label("Lower Tool", GUILayout.Width(90), GUILayout.Height(32));
    428.                 GUILayout.Box(minus, toolButtons, GUILayout.Width(60), GUILayout.Height(60)); //Blank
    429.                 GUILayout.EndVertical();
    430.             }
    431.  
    432.             GUILayout.EndVertical();
    433.         }
    434.         else
    435.         {
    436.             GUILayout.BeginVertical();
    437.             GUILayout.Label("Hill Tool", labelStyle, GUILayout.Width(70), GUILayout.Height(32));
    438.             GUILayout.Box(hillIconToUse, toolButtons, GUILayout.Width(80), GUILayout.Height(80)); //Blank
    439.  
    440.             if (!flatTool)
    441.             {
    442.                 GUILayout.BeginVertical();
    443.                 GUILayout.Label("Lower Tool", labelStyle, GUILayout.Width(90), GUILayout.Height(32));
    444.                 if (GUILayout.Button(minus, GUILayout.Width(60), GUILayout.Height(60))) //Blank
    445.                 {
    446.                     raiseTool = false;
    447.                     lowerTool = true;
    448.                 }
    449.                 GUILayout.EndVertical();
    450.             }
    451.             else
    452.             {
    453.                 GUILayout.BeginVertical();
    454.                 GUILayout.Label("Lower Tool", GUILayout.Width(90), GUILayout.Height(32));
    455.                 GUILayout.Box(minus, toolButtons, GUILayout.Width(60), GUILayout.Height(60)); //Blank
    456.                 GUILayout.EndVertical();
    457.             }
    458.  
    459.             GUILayout.EndVertical();
    460.         }
    461.  
    462.         if (currentTileSet.hasCliff)
    463.         {
    464.             GUILayout.BeginVertical();
    465.  
    466.             GUILayout.Label("Cliff Tool", labelStyle, GUILayout.Width(70), GUILayout.Height(32));
    467.  
    468.             if (GUILayout.Button(CliffIconToUse, toolButtons, GUILayout.Width(80), GUILayout.Height(80))) //Button
    469.             {
    470.                 flatTool = false;
    471.                 inclineTool = false;
    472.                 hillTool = false;
    473.                 cliffTool = true;
    474.  
    475.                 //Cannot use a height altering tool without determining which direction to alter the height.
    476.                 //This method may prove troublesome later if made to be modular.
    477.                 if (!raiseTool && !lowerTool)
    478.                     raiseTool = true;
    479.             }
    480.             GUILayout.EndVertical();
    481.         }
    482.         else
    483.         {
    484.             GUILayout.BeginVertical();
    485.             GUILayout.Label("Cliff Tool", labelStyle, GUILayout.Width(70), GUILayout.Height(32));
    486.             GUILayout.Box(CliffIconToUse, toolButtons, GUILayout.Width(80), GUILayout.Height(80)); //Blank
    487.             GUILayout.EndVertical();
    488.         }
    489.  
    490.         GUILayout.EndHorizontal();
    491.         GUILayout.EndArea();
    492.     }
    493.  
    494.     //////////////////////////////////////////////Terrain Tool/////////////////////////////////////////////////////
    495.  
    496.  
    497.     //////////////////////////////////////////////////Cast Ray////////////////////////////////////////////////////
    498.  
    499.     [CustomEditor(typeof(Tile))]
    500.     public void OnSceneGUI()
    501.     {
    502.         Debug.Log("Firing Ray");
    503.  
    504.         Ray ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
    505.         RaycastHit hit;
    506.  
    507.         if (Physics.Raycast(ray, out hit))
    508.         {
    509.             if (hit.transform.tag == "Tile")
    510.             {
    511.  
    512.                 if (flatTool)
    513.                     FlatTool();
    514.  
    515.                 else if (inclineTool)
    516.                     InclineTool();
    517.  
    518.                 else if (hillTool)
    519.                     HillTool();
    520.  
    521.                 else if (cliffTool)
    522.                     CliffTool();
    523.  
    524.                 Selection.objects = new Object[0];
    525.             }
    526.         }
    527.     }
    528.  
    529.     //////////////////////////////////////////////////Cast Ray////////////////////////////////////////////////////
    530.  
    531.  
    532.     ////////////////////////////////////////////////Flat Tool/////////////////////////////////////////////////////
    533.  
    534.     void FlatTool()
    535.     {
    536.         Debug.Log("Flat Tool");
    537.     }
    538.  
    539.     ////////////////////////////////////////////////Flat Tool/////////////////////////////////////////////////////
    540.  
    541.  
    542.     //////////////////////////////////////////////Incline Tool////////////////////////////////////////////////////
    543.  
    544.     void InclineTool()
    545.     {
    546.         if (raiseTool)
    547.             Debug.Log("Incline raise Tool");
    548.         else if (raiseTool)
    549.             Debug.Log("Incline lower Tool");
    550.     }
    551.  
    552.     //////////////////////////////////////////////Incline Tool////////////////////////////////////////////////////
    553.  
    554.  
    555.     ////////////////////////////////////////////////Hill Tool/////////////////////////////////////////////////////
    556.  
    557.     void HillTool()
    558.     {
    559.         if (raiseTool)
    560.             Debug.Log("Hill raise Tool");
    561.         else if (raiseTool)
    562.             Debug.Log("Hill lower Tool");
    563.     }
    564.  
    565.     ////////////////////////////////////////////////Hill Tool/////////////////////////////////////////////////////
    566.  
    567.  
    568.     ////////////////////////////////////////////////Cliff Tool////////////////////////////////////////////////////
    569.  
    570.     void CliffTool()
    571.     {
    572.         if (raiseTool)
    573.             Debug.Log("Cliff raise Tool");
    574.         else if (raiseTool)
    575.             Debug.Log("Cliff lower Tool");
    576.     }
    577.  
    578.     ////////////////////////////////////////////////Cliff Tool////////////////////////////////////////////////////
    579. }
     
    Last edited: May 28, 2022
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,951
    Excellent. Go make an ULTRA simple cheeseball editor window or editor script that uses the OnSceneGUI() editor to do something trivial with some dummy class, and get that fully working.

    Then reason about how that super-short simple script differs from the massive thing above.

    What is often happening in these cases is one of the following:

    - the code you think is executing is not actually executing at all
    - the code is executing far EARLIER or LATER than you think
    - the code is executing far LESS OFTEN than you think
    - the code is executing far MORE OFTEN than you think
    - the code is executing on another GameObject than you think it is
    - you're getting an error or warning and you haven't noticed it in the console window

    To help gain more insight into your problem, I recommend liberally sprinkling Debug.Log() statements through your code to display information in realtime.

    Doing this should help you answer these types of questions:

    - is this code even running? which parts are running? how often does it run? what order does it run in?
    - what are the values of the variables involved? Are they initialized? Are the values reasonable?
    - are you meeting ALL the requirements to receive callbacks such as triggers / colliders (review the documentation)

    Knowing this information will help you reason about the behavior you are seeing.

    If your problem would benefit from in-scene or in-game visualization, Debug.DrawRay() or Debug.DrawLine() can help you visualize things like rays (used in raycasting) or distances.

    You can also call Debug.Break() to pause the Editor when certain interesting pieces of code run, and then study the scene manually, looking for all the parts, where they are, what scripts are on them, etc.

    You can also call GameObject.CreatePrimitive() to emplace debug-marker-ish objects in the scene at runtime.

    You could also just display various important quantities in UI Text elements to watch them change as you play the game.

    If you are running a mobile device you can also view the console output. Google for how on your particular mobile target, such as this answer or iOS: https://forum.unity.com/threads/how-to-capturing-device-logs-on-ios.529920/ or this answer for Android: https://forum.unity.com/threads/how-to-capturing-device-logs-on-android.528680/

    Another useful approach is to temporarily strip out everything besides what is necessary to prove your issue. This can simplify and isolate compounding effects of other items in your scene or prefab.

    Here's an example of putting in a laser-focused Debug.Log() and how that can save you a TON of time wallowing around speculating what might be going wrong:

    https://forum.unity.com/threads/coroutine-missing-hint-and-error.1103197/#post-7100494

    You must find a way to get the information you need in order to reason about what the problem is.
     
  3. PawPrintProductionsLLC

    PawPrintProductionsLLC

    Joined:
    Mar 14, 2021
    Posts:
    3
    I got it working, I needed a new class and to name it TileEditor. This presents a few problems however it only fires the ray and runs the other scripts with the debug log firing before the ray. Without it I cannot get it to fire the ray.

    Edit: its working now that i zoomed in however that still makes no sense to me how the debug linbe could increase the distance of the ray. But it is working so I will take it.
     
    Last edited: May 28, 2022