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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

I need to convert my old Java script "trail system" into a C#

Discussion in 'Scripting' started by aaronhm7, Feb 6, 2019.

  1. aaronhm7

    aaronhm7

    Joined:
    Nov 4, 2016
    Posts:
    16
    hello;

    I need to know what a C# script of a "trail system" that I use to use in my games, that was a Java script and I cant use it any more because Unity is no longer using or allowing Java script,

    the Java script looks like this;

    #pragma strict

    function Start () {
    function OnTriggerStay(other: Collider) {
    if (other.attachedRigidbody)
    if (other.CompareTag ("T2")) {

    other.attachedRigidbody.transform.LookAt(target);
    }
    }

    it was a simple sysytem that I used to make a game object follow a trail system (like a way point) only it works on collision enter and tags and it was easy to set up and implicate as a trail system.

    I do not know C# and I am having trouble with the documention to try to convert my Java script into a C#

    if any one would like to take on the task of helping me convert my Java script "trail system" into a C# script,
    I would be forever greatfull...

    thak you

    Aaron Peterson
     
  2. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,380
    Kiwasi likes this.
  3. aaronhm7

    aaronhm7

    Joined:
    Nov 4, 2016
    Posts:
    16
    I am not a coder and I tried but could not learn but I can copy and paste well enough and I understand the machanics of coding, and I use to work only in java script which I understood but I am unable to figure out C# in order to make C# work, thats why I am here asking how to conveert my java script into C#

    its a simple script that I use a lot in my games and now I am unable to use it
     
  4. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,144
  5. johne5

    johne5

    Joined:
    Dec 4, 2011
    Posts:
    1,133
    here is quick conversion i did for you.
    Code (CSharp):
    1. void Start () {
    2.  
    3. }
    4. void OnTriggerStay(Collider other)
    5. {
    6.     if (other.gameObject.GetComponent<Rigidbody>())
    7.     {
    8.         if (other.gameObject.CompareTag("T2"))
    9.         {
    10.             other.attachedRigidbody.transform.LookAt(target);
    11.         }
    12.     }
    13. }
     
  6. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Don't forget you also need to do explicit class declarations, UnityScript allowed implicit class declarations.
     
  7. johne5

    johne5

    Joined:
    Dec 4, 2011
    Posts:
    1,133
    no idea what you mean by that
     
  8. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    In C# you need

    Code (CSharp):
    1. public class MyScript : MonoBehaviour {
    2. }
    In UnityScript you didn't need this at all.
     
  9. aaronhm7

    aaronhm7

    Joined:
    Nov 4, 2016
    Posts:
    16
    thank you very much,

    I have put it in mono-behavior and I have two errors;
    Code (csharp):
    1.  "void start"
    2. and "target"
    3. [code]
    4.  
    5. I cant work any more tonight,
    6. but thats a start and I can experiment with it and see what happens and I will let you know
    7. if I can get it to work
    8.  
    9. thanks again
    10. aaronhm7
     
  10. aaronhm7

    aaronhm7

    Joined:
    Nov 4, 2016
    Posts:
    16
    thank you, I have been wondering and looking for Unity to have such a conversion tool.
    I am going to miss Java enen though I knew Unity would get rid of it sooner or later
     
  11. AdrianoVerona_Unity

    AdrianoVerona_Unity

    Unity Technologies

    Joined:
    Apr 11, 2013
    Posts:
    317