Search Unity

Having porblems with monbehaviour in java script any help please!

Discussion in 'Getting Started' started by johnG0709er, Jan 11, 2019.

  1. johnG0709er


    Nov 8, 2018
    Im doing this tutorial

    and im stuck on that video when he does the randomisation script, heres the message i posted to the guy who makes the video:

    Hi jimmy when I do the script on Generate next section I get 5 errors that sais they dont like the NewAxis, TheXAxis or the NextAxis, when I put the Script on the cube it sais this error message. "Can't add script behaviour TMP_CoroutineTween. The script needs to be derived from MonoBehaviour" when looking on line ppl say you have to add a monobehaviour class to the script, but I am doing my script in java as per the tutorial and everyones answers is for C#. I dont know how to write this in Java is it var MonoBehaviour? Im a newbie I am just beginning Im one episode away from completing the game, im at a crossroads because i cant work out whats wrong, it sais it doesnt like NextAxis and TheXAxis and NewAxis. But there is no way to change it, all visual suggest is to change it from TheXAxis, NextAxis or NewAxis to Var NewXAxis : float = newFunction(); Im pretty sure that wont randomise the sections with just newFunction surely it needs to know what Axis its on to randomise the next section. The script is below, Any help would be greatly appreciated. I have worked out all other errors but i cant get my head around this one, and no one has this same problem as monodevelop still worked when this tutorial was created. now it doesnt work and the only thing you can code in is word pad and visual studio and they both give me the same errors, any help would be great. Script: var Section01 : GameObject; var Section02 : GameObject; var Section03 : GameObject; var NewXAxis : float = NextAxis.TheXAxis; var GenSec : int; var NewSec : GameObject; var NextPosition : Vector3 = Vector3(NextAxis.TheXAxis, 25.9, 16.7916); function OnTriggerEnter (col : Collider) { NextPosition = Vector3(NextAxis.TheXAxis, 25.9, 16.7916); GenSec = Random.Range(1, 4); NewXAxis = NextAxis.TheXAxis; if (GenSec == 1) { NewSec = Section01; } if (GenSec == 2) { NewSec = Section02; } if (GenSec == 3) { NewSec = Section03; } Instantiate(NewSec, NextPosition, Quaternion.identity); NextAxis.TheXAxis += 500; } any help would be great, thanks John.

    Can any one help with this, i can send the unity project over to who ever can help, i even tried converting it to C# because that has a class that sais something about monobehaviour but still didnt work and the guy who does the tutorial hasnt got back to me, any help would be great as im at a brick wall at the moment.


  2. BlankDeed


    Jul 10, 2018
    This lot aint gonna be too happy unless you mark your code with code brackets.
    JoeStrout likes this.
  3. Lurking-Ninja


    Jan 20, 2015
    who is jimmy?
  4. Kiwasi


    Dec 5, 2013
    JavaScript has been deprecated in Unity. Please move to C#.
  5. JoeStrout


    Jan 14, 2011
    This, and in addition, you'll need to provide more clues than "doesn't work."

    Imagine calling your friend who's a mechanic, and saying "My car doesn't work. Please tell me what's wrong with it." He's going to have a hard time without more to go on...
    Kiwasi and BlankDeed like this.
  6. Schneider21


    Feb 6, 2014
    Welcome to the forums!

    As @Kiwasi said, you're going to want to move away from UnityScript (aka Javascript, but it isn't) and use C#. There are converters that can mostly translate your existing code, and it's not that much more difficult to learn. You can still use tutorials aimed at UnityScript and just swap out the C# equivalent syntax in most cases.

    Please view this post on using code tags. You're not gonna get many people willing to help you if your code isn't formatted, as it's a real pain in the ass to read otherwise.

    Your wall of text contained one part that I didn't have to read past: the error message. These are always helpful and will tell you where the problem is. Learn to read them and decipher their meaning. Your says "Can't add script behaviour TMP_CoroutineTween. The script needs to be derived from MonoBehaviour". That means that your script named TMP_CoroutineTween doesn't properly inherit from MonoBehaviour.

    Are you using the newest version of Unity? If so, you actually can't use UnityScript files and are probably working in a C# file. If you're working in an older version that supports UnityScript still, maybe you created a C# file on accident? Some screenshots of your editor would help determine this.
    BlankDeed and JoeStrout like this.