Call a class from a namespace in C# from javascript

Hi,

I’m trying to call PickRandomPoint() in a C# script from a javascript …

namespace com.eliotlash.core.util {
    static class MeshExtensions {
        public const int ENTIRE_MESH = -1;

        /// <summary>
        /// Picks a random point on a mesh.
        /// This requires a lot of expensive setup so don't call in a tight loop.
        /// Instead, call the one that returns an array with the # of random points you want to pick.
        /// </summary>
        /// <returns>The random point.</returns>
        public static Vector3 PickRandomPoint(this Mesh mesh) {
            return PickRandomPoint(mesh, ENTIRE_MESH);
        }
     }
}

the above code is in the Plugin folder and my .js can see it.

I thought this would call it …

#pragma strict

import com.eliotlash.core.util;

private var spawnPointPos: Vector3;

function Start ()
{
    spawnPointPos = PickRandomPoint(mesh);
}

Also tried …

spawnPointPos = MeshExtensions.PickRandomPoint(mesh);
spawnPointPos = com.eliotlash.core.util.MeshExtensions.PickRandomPoint(mesh)

(mesh) is generated somewhere else …

Any help would be appreciated, thanks.

There’s no PickRandomPoint in com.eliotlash.core.util; it’s in the MeshExtensions class.

That would work except that the MeshExtensions class is not public. By the way, if you want to do

spawnPointPos = PickRandomPoint(mesh);

and assuming the MeshExtensions class is public, you can do

import com.eliotlash.core.util.MeshExtensions;

–Eric

@Eric5h5

Hi,

Making the MeshExtensionsclass public and using

import com.eliotlash.core.util;

and

pawnPointPos = MeshExtensions.PickRandomPoint(mesh);

I then get the error An instance of type ‘com.eliotlash.core.util.MeshExtensions’ is required to access non static member ‘PickRandomPoint’.

I then add

private var MeshExtensions : com.eliotlash.core.util.MeshExtensions;

and then i get the error NullReferenceException: Object reference not set to an instance of an object for …

spawnPointPos = MeshExtensions.PickRandomPoint(mesh);