问题描述
我一直在尝试实现这一目标,但没有成功.当我在四处搜寻时,我发现这在某种程度上是可能的,但我自己显然无法做到这一点.这是我的文件树:
I've been trying to implement this but without any success. While I was googling around I saw that this is somehow possible but I can't reach it by myself obviously. This my file tree:
|-Game
|--Assets
|---Animacije
|---Skripte
|----*BlokSistem.js
|---Standard Assets
|----*UI.boo
|---Prefabs
|---Sprites
|---Game.unity
我想在UI.boo中使用BlokSistem.js中的变量,但没有成功.我想更改一个并打印另一个.这是我现在的代码(UI.boo):
I want to use variable from BlokSistem.js in UI.boo, but without any success. I want to change one and print another. Here is my code for now (UI.boo):
import UnityEngine
import System.Collections
public class UI(MonoBehaviour):
blokSistem as BlokSistem = GetComponent[of BlokSistem]() #this is line 7 which produces error
def OnGUI() as void:
GUI.Box(Rect(0,0,200,50), "Blocks")
if GUI.Button(Rect(0,60,200,25), "Dirt = "+blokSistem.dirtAmount):
blokSistem.selectedBlock = blokSistem.dirtBlock
elif GUI.Button(Rect(0,60,200,25), "Grass = "+blokSistem.grassAmount):
blokSistem.selectedBlock = blokSistem.grassBlock
我在第7行收到此错误(在上面的代码中进行了注释):
I get this error on line 7 (commented it in code above):
The name 'BlokSistem' does not denote a valid type ('not found').
这就是我在BlokSistem.js中声明变量的方式:
This is how I declared my variables in BlokSistem.js:
public var dirtAmount : int;
public var grassAmount : int;
public var selectedBlock : GameObject;
预先感谢您的帮助.
推荐答案
这里的问题是编译顺序.在您的Boo和JS代码被编译时,它们无法相互访问.但是有一种解决方法.
The problem here is compilation order. At the time where your Boo and JS code are compiled, they don't have access to each other. But there is a workaround for that.
插件代码将在常规"代码之前编译在您的资产中.因此,如果您的Boo代码依赖于JS(UnityScript)代码中的某些内容,则可以将JS代码放入名为插件"的文件夹中.请记住,这(在逻辑上)只能以一种方式起作用.因此,如果您的JS代码曾经依赖于Boo方面的内容,那么您就不走运了.
Plugin code will be compiled before the "regular" code in your assets. So if your Boo code relies on something in your JS (UnityScript) code, you can put the JS code inside a folder named "Plugins". Keep in mind that this (logically) works only one way around though. So if your JS code ever relies on something in the Boo side, you're out of luck.
但是,这确实(如果是您自己的代码)通常暗示着切换到一种语言并坚持使用是一个好主意.并且,由于重点更多地放在C#上,而不是UnityScript上,尤其是Boo上,您可能需要考虑迁移.
This does however (if it is your own code) usually imply it's a good idea to switch to a single language and stick to it. And with focus being more on C# than on UnityScript and particularly Boo, you might want to consider moving over.
这篇关于如何在Boo中使用UnityScript中的变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!