Log in or register to post comments

Buttons in Unity

May 30, 2011 - 7:11am #1

I'm trying to create a simple button that reacts to the touchscreen of my device. I'm aiming for a simple animation that is started with the button. I'm not by any means a scripting guru, but is this easily feasible?

I found something in the unity documentation about Input. Is this the way to go?

Re: Buttons in Unity

May 31, 2011 - 2:06pm #4

Have you attached this script to the object that contains the animation component?

Take a look at the log file as you touch the button (use the DDMS tool that comes with Android). Is there a null pointer exception? Try adding a print statement, see if anything shows up in the log.

- Kim

Re: Buttons in Unity

May 31, 2011 - 4:37am #3

Thanks for the reply,

This is what i came up with, but it doesn't work. Button is displayed, but the animation won't play. "animatie2" is the name of the animation clip.

function OnGUI () {
	if (GUI.Button (Rect (10,10,150,100), "Push to Play")) {
		animation.Play ("animatie2");
	}
}

can you tell me what i'm missing?

Regards,
Thomas

Re: Buttons in Unity

May 30, 2011 - 7:44am #2

http://unity3d.com/support/documentation/ScriptReference/Input-touches.html

http://unity3d.com/support/documentation/ScriptReference/GUIElement.HitTest.html

- Kim

Log in or register to post comments