- Home /
Unity 4.6 beta button with Javascript rather than C#
I don't know how much experience you guys have with the new beta. But i am in a bad position because all the new tutorials and explanations are in C#. I should probably learn it, but i would rather not at the moment. But the new gui button has an option to fire a public class. I dont really exactly know what it is because i use Javascript. But i tried making my function a static function, did not show up, a public function, it did not show up. Is there some sort of prefix i should put before the function. Because i just want it to fire a function from a different gameobject.
Answer by Anxo · Sep 18, 2014 at 01:20 AM
I have not messed with the new Beta but I know the new GUI is based on the NGUI which I do use and its buttons trigger a public void method inside of a class.. (a function inside of a script). If you wish to continue using Javascript while using these buttons you could write a small C# script that just sends button calls along but it would be very inconvenient. Something like this.
// All scripts in C# and this stuff.
using UnityEngin;
using System.Collection;
public Class ButtonExtention : Monobehaviour {
/// Here is where the actual script is. where all the content goes.
public GameObject JavascriptButtonReciver;
public void ButtonA{
// Button A was pressed, Send it to the javascript
JavascriptButtonReciver.BroadcastMessage("ButtonA");
}
public void ButtonB{
// Button B was pressed.
JavascriptButtonReciver.BroadcastMessage("ButtonB");
}
}
This would allow you to make as many public voids receivers as you want and then have the message relayed to your javascript as "BraodcastMessage" works the same in Javascript as it does in C# so you can broadcast messages from one to the other.
Forgive the errors as I am not near Unity to test the code. But you get the idea.
I am sure the developers of unity have sort of implemented something so that us javascript coders can actually make use of the new features. I see what you are saying in the script you wrote, but this might be too much work for something that might be pretty simple
Its not? I thought the they hired the guys who made NGUI to make the new GUI system. It even looks very similar in the videos.
He initially worked on that but later he left and since then Unity GUI has deviated from NGUI a lot.
To quote Aron $$anonymous$$ook (NGUI guy) from his forum itself (New Unity GUI and NGUI):
I left Unity back at the end of November last year after working there for 13 months. NGUI and uGUI are completely different systems now and I can't comment much on uGUI beyond what was said in the past. I'll leave the talking to those who are actively developing it (and there are quire a few very talented guys on it).
I am focusing on NGUI because it's also what I am using myself in my own projects (currently Windward). The development / fixes / polish happen naturally.
Answer by orb · Sep 18, 2014 at 01:40 AM
Well, you can do it the same way as in C#:
#pragma strict
import UnityEngine.EventSystems;
class Filth extends MonoBehaviour implements IPointerEnterHandler
{
function OnPointerEnter(data : PointerEventData)
{
Debug.Log(data.position.x+", "+data.position.y);
}
}
You can implement any of the events like that. You just need to explicitly declare a class and not lazily just fill a file with methods. But now you're getting close to the verbosity of C# and still not getting faster compile times or namespaces ;)