the second image is how it is supposed to look like, the first one is how it looks like, and on mobile I just see the red part
but the main issue is that button dont work, on desktop they get highlighted when clicking on them but they do nothing and on mobile they just do nothing
Hey, this is not enough information to help you.
Is there a link to see the behaviour? What are you trying to achieve? What did you try and which components did you use / how is your scene hierarchy setup? Which version of Needle are you using?
yeah sure, I’m using unity 6 and I belive the newest version of needle
here is a link to the project, excuse the bad ui
I tried using a sample project but still to no avail
I did learn however that directly adding an onclick event that disables an object does work but adding an onclick event to my own custom function does not
so I guess that’s the main issue now, why can’t I use my own functions in an on click event
btw this is the test fucntion i made
public void kill()
{
gameObject.SetActive(false);
}
You can assign your own functions to click events too, no problem
For example just add this script to the same object that has the button:
import { Behaviour, Button } from "@needle-tools/engine"
export class ClickExample extends Behaviour {
awake() {
const button = this.gameObject.getComponentInChildren(Button);
button?.onClick.addEventListener(() => console.log("BUTTON CLICKED!"));
}
}
Or you can assign the button reference from Unity.
The code you shared doesnt provide enough context besides being C# - You have to write code in Typescript or Javascript. Please checkout the docs for scripting: Creating and using Components | Needle Engine Documentation
wait I can’t use C#? so is that the issue, oh guess I have to use typescript or javascript, so do I just program the whole app using one of these languages?
Yes, you need to use Typescript or Javascript if you need to write custom code: Creating and using Components | Needle Engine Documentation
ok I’ve done this
import { Behaviour, serializable } from “@needle-tools/engine”;
// Documentation → Creating and using Components | Needle Engine Documentation
export class buttonButWorks extends Behaviour {
@serializable(GameObject)
normalMenu!: GameObject;
@serializable(Button)
button!: Button;
start() {
}
awake() {
button?.onClick.addEventListener(() => specificItem());
}
specificItem()
{
console.log("BUTTON CLICKED!");
normalMenu.activeSelf = false;
}
}
I click the button and nothing happens, it’s supposed to disable the menu
(the button is the third pizza to the right)
btw, in the website there isn’t a console right?
one last thing, the code doesn’t work in the editor but I assume Type script only works whn building to the web
one more question when I tried opeing the script i made it opens this
// NEEDLE_CODEGEN_START
// auto generated code - do not edit directly
#pragma warning disable
namespace Needle.Typescript.GeneratedComponents
{
public partial class buttonButWorks : UnityEngine.MonoBehaviour
{
public UnityEngine.GameObject @normalMenu;
public UnityEngine.UI.Button @button;
public void start(){}
public void awake(){}
public void specificItem(){}
}
}
// NEEDLE_CODEGEN_END
same name but in c#, I guess this the way needle translates it but how can i access the typescript i wrote?
oh, the console doesnt give me any errors so i’m guessing my cde had a lot of them, why can’t i see the errors?
ok ok ok I think I have resolved the issues, will come bac tomorrow with the answers as it’s getting late