Search Unity

Had to convert JS script to C# - thanks Unity ... NOT!!!

Discussion in 'Scripting' started by Elowan, Dec 27, 2017.

  1. Elowan

    Elowan

    Joined:
    Aug 14, 2013
    Posts:
    106
    hello there,

    I am forced to convert a js script to c#, to have assets listed in the store, after Dec31...

    Seems, a simple conversion on http://www.m2h.nl/files/js_to_c.php does not work well - great :/

    Can someone please explain, what´s wrong with the C# script-conversion?

    With the old JS script, I was able to drag´n´drop terrians into "slots" on the inspector-window, to setup neighboring terrains.



    At runtime, the script eliminates those ugly LOD seams (that are still present in the lates unity-version, congratz!) and it was ruinning fine.

    With the converted C# script, I get no "slots" to drag the terrains into *grrrr*

    What is going on with this? Is there some code-genius out there, that can help me out on this one?
    I am more of an Artist, coding is not my domain...

    the JS script:

    Code (JavaScript):
    1. #pragma strict
    2.  
    3. var terrainLeft : Terrain;
    4. var terrainTop : Terrain;
    5. var terrainRight : Terrain;
    6. var terrainBottom : Terrain;
    7. function Start()
    8. {
    9. var thisTerrain : Terrain = GetComponent(Terrain); thisTerrain.SetNeighbors( terrainLeft, terrainTop, terrainRight, terrainBottom);
    10. }
    the converted C#:

    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class TerrainStitcher : MonoBehaviour
    6. {
    7.     Terrain terrainLeft;
    8.     Terrain terrainTop;
    9.     Terrain terrainRight;
    10.     Terrain terrainBottom;
    11.  
    12.     void Start()
    13.     {
    14.         Terrain thisTerrain = GetComponent<Terrain>();
    15.         thisTerrain.SetNeighbors(terrainLeft, terrainTop, terrainRight, terrainBottom);
    16.     }
    17. }
    Kind Regards !
     
  2. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    add public or [SerializeField] to your variables. They are private right now, and therefore do not show up in the inspector.
     
  3. Elowan

    Elowan

    Joined:
    Aug 14, 2013
    Posts:
    106
    awesome man, you rock !

    adding "public" was key - now everythings works as it used to :)

    thanks a ton
     
  4. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    No problem, you're welcome. :)

    You'll get used to c# with a bit of practice.