[SOLVED] Can't find Javascript Reference from a C# Script

Hi Unity friends!!

I am having some trouble with my game. I have a javascript named Logica.js, this script contains some state and gameplay variables i need, I also have a GameObject with the Logica.js script attached to it.

On the other hand, I made a class called InterfaceManager.cs, this C# script has all the code i need to make some sprites for my interface using SpriteManager.

My problem comes with a specific sprite i need to show or hide at an specific time. To do so, i need to have a reference to the Logica object in my InterfaceManager script.

I have tried the following

public class InterfaceManager : MonoBehaviour {
	//Manager
	public SpriteManager spManager;
	public SpriteInfo spInfo;
	public Logica logica;

but Unity says "The type or namespace name ‘Logica’ could not be found, so I tried writing

using Logica;

But I got the same error. then I tried making the variable logica of GameObject type, and then in the awake function, tried to get the Logica component.

logica.GetComponent(typeof(Logica) as Logica);

but the same error appears.

Please if some one knows how to correctly get the reference, i will be very grateful.

Thank you all!

Argilliath.

Check this out:

That explains what to do when you have a C# and a JS script trying to reference each other. Basically your C# script doesn’t realize there is a class ‘Logica’, because it has to be placed in a specific folder, explained by that reference link.

Hi Tempest!

Thanks a lot, but that doesn’t seems to work, I am in Unity Iphone right now, and the only folder i have is Assets, since i made an empty project. I tried to make the Standard Assets Folder, and placed the scripts accordingly, but then the Logica.js script i placed there doesn’t appear in my project, I imported it but the same error “The type or namespace name of ‘Logica’ could not be found” pops up again.

Thanks a lot again, hope some one can help me.

Argilliath

Hi Unity guys!

I wasn’t able to cope with the folders issue, but i was able to make things work by using the GameComponent.SendMessage() function, now I have a reference to the InterfaceManager.cs script in the Logica.js script.

public var interfaz : GameObject;

the interfaz variable has the connection to the InterfaceManagerScript.

		if (estado == EstadosLogica.SAQUE_LOCAL_INICIADO || estado == EstadosLogica.SAQUE_LOCAL_DRAGGING) {
			interfaz.SendMessage("setAnimation", true);
			interfaz.SendMessage("mostrarBarraSaque");
			ultimoEstado = estado;
		}

and with that method now my animation activates or deactives according to the estado (state) variable.

Thanks for the help!

Argilliath

your link is dead what did it say ?

The link is dead because this thread is from 8 years ago. Tempest last logged in 6 years ago, so good luck waiting for his answer.

The answer today should be JS / UnityScript is deprecated in Unity. You should be focused on switching your JS scripts to C# instead of continuing to work on compatibility issues, as at some point in the near future they will cease to work entirely anyway.

2 Likes

thank you for your time

Its actually still in the current documentation.

But I strongly agree with @Joe-Censored , you should be working to convert your scripts over to C#. UnityScript is dead.

2 Likes