简体   繁体   English

Unity3D,如何从C#类调用Unityscript类?

[英]Unity3D, how to call Unityscript class from C# class?

i had found an Inventory system from the Asset Store, but it just provide Unityscript (c# seems like got problem, cant work). 我从Asset Store找到了一个库存系统,但是它只是提供Unityscript(C#似乎有问题,无法正常工作)。 So i try to use my project call the class, means use C# to call Unityscript class. 因此,我尝试使用我的项目调用类,即使用C#调用Unityscript类。

Below is one of the proper file to call the function i need. 以下是调用我所需功能的适当文件之一。

static var playersinv : Inventory; //THIS IS THE CLASS i want to call,

function MoveMeToThePlayer(itemHolderObject : Transform)
{
    //Cut off the code for avoid the coding too long
}

After that, i learn how to call the Unityscript file from C#, base on this URL I had put the Inventory class in to Standard Asset, so the error i gone. 之后,我学习了如何从C#调用Unityscript文件,基于这个URL,我将Inventory类放入了Standard Asset,所以错误消失了。 But when i call the file, it return null. 但是,当我调用该文件时,它返回null。 so is that any one can show me where i wrong or what i should do? 那么有人可以告诉我我在哪里错了或者我应该怎么做吗? thanks. 谢谢。

below is my code 下面是我的代码

Transform EquipmentItem;
    private Inventory Inv;

    private Rect rctWindow;

    // Use this for initialization
    void Start () {
        rctWindow = new Rect(350, 150, 230, 100);
        EquipmentItem = gameObject.transform.Find ("Medieval Sward");
        print (EquipmentItem);
        Inv = FindObjectOfType (Inventory); //I TRY To follow the Javascript wall to call, but not works
        //Inv.AddItem(EquipmentItem);
        Inv = (Inventory) gameObject.GetComponent("Inventory");//Follow the website example, but i fail
        print (Inv);
    }

thanks for helping! 感谢您的帮助!

if the Javascript class contains the function or variable, and you want to call it from a C# script, it's the Javascript script which must go in an earlier-pass folder or if the C# class contains the function or variable, and you want to call it from a Javascript script, it's the C# script which must go in an earlier-pass folder so for example put js in Plugins folder and put c# in Plugins/Editor and test it 如果Javascript类包含函数或变量,并且您想从C#脚本中调用它,则该Javascript脚本必须放在较早通过的文件夹中,或者如果C#类包含函数或变量,并且您想调用它是来自Javascript脚本,它是C#脚本,必须放在早期传递的文件夹中,因此例如将js放在Plugins文件夹中,然后将c#放在Plugins / Editor中进行测试
compilation order 编译顺序

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM