Category Archives: Development

Unity3D and Raycasts in a 2D Scene

Note to self: When using RaycastHit2D in Unity make sure that the GameObjects you’re attempting to collide with have a Rigidbody component or those rays are going to shoot right on through!  In a 2D scene where you’re not bothered about gravity its helpful to make those Rigid bodies kinematic as well else they’ll fall to nowhere. #stilllearning

An example detecting a GameObject located below a touch event:

 

Touch touch = Input.touches [0];

Ray ray = Camera.main.ScreenPointToRay(touch.position);
RaycastHit2D hit = Physics2D.GetRayIntersection(ray);

if (hit) {
    Debug.Log ("Hit: " + hit.transform.gameObject.name);
    // Do something with the GameObject...
}

SQL COALESCE function

Today I discovered the SQL function ‘COALESCE’.  The function returns the value with the highest precedence datatype from a comma separated list of expressions.  For example:

SELECT COALESCE (site_settings.VALUE, settings.VALUE) AS VALUE
FROM site_settings
LEFT JOIN settings ON settings.id = site_settings.setting_id

In the above example the first non NULL value passed to the COALESCE function is selected. if site_settings.value is NULL then settings.value will be selected. If settings.value is NULL, then the site_settings.value will be selected. If both values are NULL, then NULL will be returned.

Here is the MySQL reference page for the function: COALESCE

Worth keeping in mind. Came in handy for simplifying some SQL at work.