Domanda

I want to call C# function from a UnityScript GameMaster.js like this.

GameMaster.js

#pragma strict

function Start () {
  print(Mahjong.Foo());
}

Mahjong.cs

using System.Collections;

public class Mahjong {
  string Foo () {
    return "foo";
  }
}

When I run the program, I get BCE0005: Unknown identifier: 'Mahjong'.. According to information from here, if script files are in Assets directory, I don't need to import file.

But it doesn't works in my case. what am I missing? How can I call #C's function from UnityScript?

È stato utile?

Soluzione

The C# script has to be compiled before the JS script for this to work. To achieve this you have to move the C# script into one of the following directories: Plugins, Standard Assets or Pro Standard Assets.

It also works the other way around - if you want to call JS from C#, move the JS into one of the folders.

It does not work both ways at once however.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top