- Home /
4.6 how to scale Box Collider2d with screen size?
Hello
i am using the anchors method and Scale With Screen Size from the canvas to scale any image on any resolution but the problem is the collider stays at the same size.
Comment
Answer by abi-kr01 · Feb 06, 2015 at 04:42 AM
m not sure this will resolve your issue or not but you can add collider after you render image scale up/down like
void Start()
{
//when unity starts it will scale image after that start is called you need to add collider to images via script
// which will be perfect size collider
}
Start is called after the scaling of anchors and images?
also how can i change the size of collider from script
Answer by Noob_Vulcan · Feb 06, 2015 at 05:12 AM
If its only about UI Element then you can add Selectable Script to the image (remove collider).
and add a script that implements the pointerlisteners
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class Test : MonoBehaviour,IPointerDownHandler {
#region IPointerDownHandler implementation
public void OnPointerDown (PointerEventData eventData)
{
Debug.Log (eventData);
//This will be called on touching the image
}
#endregion
}
There are many other ways to achieve it. Hope this helps
Your answer