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

I need to Call a C# function to my JavaScript function

Discussion in 'Scripting' started by ochoag, Mar 19, 2016.

  1. ochoag

    ochoag

    Joined:
    Mar 19, 2016
    Posts:
    25
    I have been trying to call a function of c# to my JavaScript GameState:

    this function:

    with this variables:

    bool _isWon;
    bool _isLost;

    void Update ()
    {
    if (LevelManager.Instance.IsLevelRunning && (_isWon || _isLost))
    {
    Assert.IsTrue(LevelManager.IsActive, "Please ensure that you have a LevelManager component added to your scene.");
    Assert.IsTrue(GameOver.IsActive, "Please ensure that you have a GameOver component added to your scene, or are using one of the default GameOver prefabs.");

    LevelManager.Instance.LevelFinished();
    GameOver.Instance.Show(_isWon);
    }
    }

    or

    void Update ()
    {
    if (LevelManager.Instance.IsLevelRunning && (_isWon || _isLost))
    {
    Assert.IsTrue(LevelManager.IsActive, "Please ensure that you have a LevelManager component added to your scene.");
    Assert.IsTrue(GameOver.IsActive, "Please ensure that you have a GameOver component added to your scene, or are using one of the default GameOver prefabs.");

    LevelManager.Instance.LevelFinished();
    GameOver.Instance.Show(_isLost);
    }
    }

    everything to call that Game is Over or Game is Won but in my GameState JavaScript I have the functionally of GAME the only that I want is call these function to my part:



    function Update ()
    {

    if(vida <=0)
    {
    here when is Lost
    }

    if(timer <=0 && puntos >= 50)
    {
    here when is Won

    }
    if(timer <=0 && puntos < 50)
    {

    here when is Lost
    }
    print("Puntuacion: "+puntos);
    print ("Vidas: "+vida);

    }

    someone can help me in these part.??? I have been searching but not have found the solution for my problem....
     
  2. MrEsquire

    MrEsquire

    Joined:
    Nov 5, 2013
    Posts:
    2,712
    Think you posted in wrong forum section
     
  3. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,663
    ochoag likes this.
  4. ochoag

    ochoag

    Joined:
    Mar 19, 2016
    Posts:
    25
    so in what section will be?
    Thanks!! For help and yes since beginning I started programming in JavaScript more I had to use C# in some situations...I know what happen.
     
  5. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,663
    I prefer C# but I wont try to sell you on it, it really depends which comes more naturally to you and they are similar enough that ultimately it comes down to what you can do with the language anyway. Good luck!
     
    ochoag likes this.