简体   繁体   中英

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). So i try to use my project call the class, means use C# to call Unityscript class.

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. But when i call the file, it return 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
compilation order

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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