Log in or register to post comments

What is the namespace to import for UnityScript?

November 6, 2013 - 12:16pm #1

When the trackable is no longer detected, the objects in my scene that follow physics are falling because there is no longer a support underneath them from my virtual terrain. I found out I can parent my game object to the ImageTarget prefab and when the trackable isn't detected, the game objects are also removed from the scene so they don't end up falling down. How can I do this at runtime though? I am looking at the API, and I have created the following code to query for which trackable is being detected and parenting my game objects to it when I added them:

 

function parentToTrackable(transform : Transform){
	var imageTargetBehaviours : ImageTargetBehaviour[] = FindObjectsOfType(ImageTargetBehaviour) as ImageTargetBehaviour[];
	for(var imageTargetBehaviour : ImageTargetBehaviour in imageTargetBehaviours){
		f(imageTargetBehaviour.CurrentStatus == TrackableBehaviour.Status.DETECTED)
			transform.parent = imageTargetBehaviour.object;
	}
}

 

But I am not able to test this because I don't know what the namespace is I need to import into my script. I know that ImageTargetBehavior is a C# file, but is there a way I can use it in my JavaScript script? Sorry if that's a very basic question!

What is the namespace to import for UnityScript?

November 7, 2013 - 11:21am #4

Oh and in case it helps someone, it looks like in Mono, the directories under your solution are arranged by compilation order, with the first being the first on the list.

What is the namespace to import for UnityScript?

November 6, 2013 - 2:16pm #3

Okay thanks for the link. I was able to cut and paste the ImageTargetBehaviour.cs file into the Standard Assets and now the code that I posted runs and compiles. It will also work for the purpose I had stated, you just have to change the state checked from DETECTED to TRACKED, in case that helps someone else too. :)

What is the namespace to import for UnityScript?

November 6, 2013 - 12:39pm #2

Are you getting a Can't Find Namespace error? - that's due to Unity's script compilation order and the fact that the referenced C# classes need to be compiled prior to referencing them in Javascript.

See:

http://answers.unity3d.com/questions/10856/cant-find-namespace-accessing-javascript-from-c-or.html

If at all possible, use C#, otherwise you'll need to restructure your project to allow you to use Javascript.

Log in or register to post comments