- Home /
uGUI Button with collider bigger than sprite
Like written in the title. Is there any way to create an uGUI button with a collision area bigger than the sprite? I am using unity 4.6 beta v18 I explored the possibility of scripting the collision area but due to the way IsRaycastLocationValid works its not possible (obviously) to detect something beyond the borders of the sprite.
Is there any method that can help me that I don't know of?
Answer by kjuanlu · Oct 14, 2014 at 12:59 PM
I just tryed this and worked for me:
-Add this scrip:
#pragma strict
@script ExecuteInEditMode()
public class SimpleGraphic extends UI.Graphic{
protected function OnFillVBO (vbo : List.<UIVertex> ){
}
}
-Crate a UI.Image (this will be renderer as button)
-Create a UI.Button (this will be invisible)
-Remove the UI.Image from the button, and add the new SimpleGraphic component
-Set Target Graphic to the UI.Image gameObject
You can manipulate the size of both gameObjects independently.
I checked that the new SimpleGraphic component has no drawcall costs (no vertex, no tris)
Works great, Thanks!
C#:
[ExecuteInEdit$$anonymous$$ode]
public class SimpleGraphic : UnityEngine.UI.Graphic
{
protected override void OnFillVBO(System.Collections.Generic.List<UIVertex> vbo)
{
}
}
Answer by AyAMrau · Sep 03, 2014 at 10:11 PM
Unfortunately it doesn't look like there is a easy and clean solution for this.
The quick solution: You can make invisible buttons with transparent sprites (or normal sprites but the color alpha set to 0), it's rather hacky, but does the job.
The clean solution: Make your own class extending the BaseRaycaster and come up with your own way of doing this.