首页 \ 问答 \ 如何在Boo中使用UnityScript中的变量?(How to use variables from UnityScript in Boo?)

如何在Boo中使用UnityScript中的变量?(How to use variables from UnityScript in Boo?)

我一直试图实现这一点,但没有任何成功。 当我在谷歌上搜索时,我发现这在某种程度上是可能的,但显然我无法达到它。 这是我的文件树:

|-Game
|--Assets
|---Animacije
|---Skripte
|----*BlokSistem.js
|---Standard Assets
|----*UI.boo
|---Prefabs
|---Sprites
|---Game.unity

我想在UI.boo中使用BlokSistem.js中的变量,但没有任何成功。 我想换一个并打印另一个。 这是我现在的代码(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行得到此错误(在上面的代码中注释):

The name 'BlokSistem' does not denote a valid type ('not found'). 

这是我在BlokSistem.js中声明我的变量的方式:

public var dirtAmount : int;
public var grassAmount : int;
public var selectedBlock : GameObject;

在此先感谢您的帮助。


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

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

I get this error on line 7 (commented it in code above):

The name 'BlokSistem' does not denote a valid type ('not found'). 

This is how I declared my variables in BlokSistem.js:

public var dirtAmount : int;
public var grassAmount : int;
public var selectedBlock : GameObject;

Thanks in advance for help.


原文:https://stackoverflow.com/questions/28274895
更新时间:2023-04-11 13:04

最满意答案

是否与下面的查询相同?

如果我想使用OR(||)运算符获取数据,该怎么办?

它的资源成本远低于此:

IQueryable<Ad> list1 = db.Ads.Where(x=>x.isModerated);
IQueryable<Ad> list2;

if(something == true)
{
    list2 = list1.Where(x=>x.TypeId == 2) 
}
else 
{
    list2 = db.Ads.Where(x=>x.isModerated  || x.TypeId == 2)  
}

但如果由于某种原因你不想这样做,你可以这样做:

list2 = list1.Union(db.Ads.Where(x=> x.TypeId == 2)) 

会给你相同的结果集


is it going to be the same as query below?

Yes

and what if I would like to get a data using OR (||) operator is the same scenario.

Its going to be far less resource expensive to do it like:

IQueryable<Ad> list1 = db.Ads.Where(x=>x.isModerated);
IQueryable<Ad> list2;

if(something == true)
{
    list2 = list1.Where(x=>x.TypeId == 2) 
}
else 
{
    list2 = db.Ads.Where(x=>x.isModerated  || x.TypeId == 2)  
}

But if for some reason you do not want to do it that way you could do it:

list2 = list1.Union(db.Ads.Where(x=> x.TypeId == 2)) 

will give you the same result set

相关问答

更多
  • 更改 let mutable cars = List() :> ICollection 至 let mutable cars = Unchecked.defaultof> 和 let mutable dealer = Dealer() 至 let mutable dealer = Unchecked.defaultof Change let mutable cars = List() :> ICollection< ...
  • 您可以像这样访问通用的Set方法: var entities = (from e in myContext.Set()); 更新:您需要向方法添加泛型类型约束,以确保泛型类型T将匹配已应用于方法DbContext.Set的约束。 更新2:您不需要投射您的实体; 它已经是typeof(T) 。 public T GetEntity(Guid entityId, string connectionString) where T : class { using (RContex ...
  • 是否与下面的查询相同? 是 如果我想使用OR(||)运算符获取数据,该怎么办? 它的资源成本远低于此: IQueryable list1 = db.Ads.Where(x=>x.isModerated); IQueryable list2; if(something == true) { list2 = list1.Where(x=>x.TypeId == 2) } else { list2 = db.Ads.Where(x=>x.isModerated || x.T ...
  • 是。 千条条款可以影响绩效。 如果可以,我建议使用值创建一个临时表,并使用逻辑连接。 您应该在临时表上创建索引。 注意:您可以在主表上使用技巧,方法是添加一个将列值连接在一起的计算列。 然后用于: alter table t add ab as (a + ':' + b); create index idx_t_ab on t(ab); 然后将查询修改为: where ab in ('1:2', . . . ) 这对所有应用程序都不适用,但它可能适合您的性能需求。 Yes. A thousand wh ...
  • 你把Where放在第一位然后Max就像这样 int max = DbContext.myTable.Where(it=>it.columnB>5 && it.ColumnC=1).Max(t => t.ColumnA); You put Where first and then Max later like this int max = DbContext.myTable.Where(it=>it.columnB>5 && it.ColumnC=1).Max(t => t.ColumnA);
  • 对我来说,它看起来像userName , roles和applications是查询的参数,即数据来自您的应用程序而不是来自数据库。 在这种情况下,我会写这样的查询: IQueryable query = cnt.Users; if(userName != null) query = query.Where(x => x.name == userName) if(roles.Any()) query = query.Where(x => roles.Contains(x.role ...
  • 您可以使用Sql方法在Migration中创建视图: public partial class Migration : DbMigration { public override void Up() { this.Sql("CREATE VIEW dbo.MyView AS (etc)"); } public override void Down() { this.Sql("DROP VIEW dbo.MyView"); } ...
  • 在查询期间,您无法比较RavenDB中的两个值。 您无法做到这一点的原因是,这需要数据库引擎扫描所有文档以查找匹配项。 相反,创建一个索引,在索引时进行比较,并查询结果。 You cannot compare two values in RavenDB during query. The reason you cannot do that is that this requires the database engine to scan through all the documents to find m ...
  • 使用SelectMany而不是Select project.ProjectDoc .SelectMany(c => c.Comment.Select(i => i.UserID)) .Distinct() .Count() Use SelectMany instead of Select project.ProjectDoc .SelectMany(c => c.Comment.Select(i => i.UserID)) . ...
  • Any()根本不返回值 - 它返回一个布尔值,表示集合中是否有值。 它只显示两个值,因为您只查询CmsContents,它有两行,并且两行至少有一个类别,所以两行都在结果中。 看起来你真的喜欢: var contents = from cnt in context.CmsContents from category in cnt.CmsCategories select cnt; Any() doesn't return values at al ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。