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. Dismiss Notice

Access variable from c# to js

Discussion in 'Editor & General Support' started by Clavery, Apr 22, 2014.

  1. Clavery

    Clavery

    Joined:
    Jan 8, 2014
    Posts:
    8
    Hello. I have playerSettings.js and gameOverMenu.cs scripts. I need get point from playerSettings.js to gameovermenu.cs
    But my code not work. I need some help I dont know c#. Sorry for my bad english.

    My code :
    (playerSettings.js and gameOverMenu.js in the Assets folder. After I created Plugins folder and transfer scripts but not work )
    Code (csharp):
    1. public class gameOverMenu : MonoBehaviour {
    2. playerSettings getPoint;
    3. void Update () {
    4. getPoint = this.GetComponent<playerSettings>();
    5. }
    6. }
    Error :
    Code (csharp):
    1. Assets/gameOverMenu.cs(5,9): error CS0246: The type or namespace name `playerSettings' could not be found. Are you missing a using directive or an assembly reference?
     
  2. drewradley

    drewradley

    Joined:
    Sep 22, 2010
    Posts:
    3,063
    Try "this.transform" rather than just "this". I could be wrong but I think the way you did it means it's looking on the script for the component.
     
  3. Clavery

    Clavery

    Joined:
    Jan 8, 2014
    Posts:
    8
    Thanks for reply but still not work
     
  4. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
    Using C# and JS in the same project is problematic.

    On of the two is compiled first and does not know the other languages classes:

    http://www.41post.com/1935/programming/unity3d-js-cs-or-cs-js-access