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.
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.
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.
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.
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.