Search Unity

Couple of questions about CS scripts and java scripts

Discussion in 'Scripting' started by ratamorph, Dec 26, 2007.

  1. ratamorph

    ratamorph

    Joined:
    Sep 2, 2007
    Posts:
    458
    I was wondering if you could access a cs script from a javascript and vice versa, I tried this....

    script = someObject.GetComponent(someCsScript);

    this gave me compiler errors, the errors went away when I tried accesing a javascript instead like this...

    script = someObject.GetComponent(someJavaScript);

    So can you access a cs script from within a java script file? if so how do you do it?

    Also I noticed the cs scripts don't have the enabled checkbox in the inspector, why is this?

    As always thanks for all the help.
     
  2. freyr

    freyr

    Joined:
    Apr 7, 2005
    Posts:
    1,148
    See the scripting documentation on compilation order. The javascript you want to access from C# (or vice versa) has to be compiled before the script you are using it from.

    Re. the enabled flag. All script inheriting from MonoBehaviour should have a enabled flag. Did you ensure that your C# script inherits from MonoBehaviour? Also check if all scripts compiled without errors.
     
  3. NCarter

    NCarter

    Joined:
    Sep 3, 2005
    Posts:
    686
    Isn't it the case that the enabled checkbox now only appears if you implement one of the event methods that it affects, such as Start or Update? I think that was one of the changes made for 2.0.
     
  4. ratamorph

    ratamorph

    Joined:
    Sep 2, 2007
    Posts:
    458
    Thanks for que quick feedback guys, I overlooked that part in the documents.