[Unity C#] Raycast & LayerMask

float myVisionDistance = 50;
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
RaycastHit hit;
int t_layerMask = (int) Mathf.Pow (2, 8); //for the layer you want to do the raycast
if (Physics.Raycast (ray, out hit, myVisionDistance, t_layerMask))
if (hit.collider.tag == "Food") {
    myTargetPosition = hit.transform.position;
}

Calculate layerMask:
If you want to do the raycast on layer 1,4&8,

    layerMask = (int) (
        Mathf.Pow (2, 1) + 
        Mathf.Pow (2, 4) + 
        Mathf.Pow (2, 8)
    )

[Unity Reminder] Collider

void OnCollisionEnter (Collision collision)
void OnCollisionStay (Collision collision)
void OnCollisionExit (Collision collision)

void OnTriggerEnter(Collider other)
void OnTriggerStay(Collider other)
void OnTriggerExit(Collider other)

void OnCollisionEnter2D (Collision2D coll)
void OnCollisionStay2D (Collision2D coll)
void OnCollisionExit2D (Collision2D coll)

void OnTriggerEnter2D (Collider2D other)
void OnTriggerStay2D (Collider2D other)
void OnTriggerExit2D (Collider2D other)

[Unity C#] Create Grids in Unity Editor

[Unity C#] Create Grids in Unity Editor
//Created by Tim & Hang
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[ExecuteInEditMode]
public class CS_GridSetup : MonoBehaviour {

    [SerializeField] bool createGrids = false;

    [SerializeField] GameObject myGridPrefab;

    [SerializeField] int myColumns = 16;
    [SerializeField] int myRows = 9;

    [SerializeField] Vector2 myBottomLeft = new Vector2 (-8, -4);
    [SerializeField] Vector2 myTopRight = new Vector2 (8, 4);
    [SerializeField] float myPositionZ = 10;

    private List<GameObject> myGrids = new List<GameObject> ();


    // Update is called when something changes in the scene
    void Update () {
        if (createGrids == true) {
            createGrids = false;

            //Clear the existing grids

            foreach (GameObject t_grid in myGrids) {
                GameObject.DestroyImmediate (t_grid);
            }
            myGrids.Clear ();

            //create grids

            for (int i = 0; i < myRows; i++) {
                for (int j = 0; j < myColumns; j++) {
                    Vector3 t_position = new Vector3 (
                                             (myTopRight.x - myBottomLeft.x) / (myColumns - 1) * j + myBottomLeft.x, 
                                             (myTopRight.y - myBottomLeft.y) / (myRows - 1) * i + myBottomLeft.y,
                                             myPositionZ); //Calculate the position
                    GameObject t_grid = Instantiate (myGridPrefab, t_position, Quaternion.identity); //Create the grid
                    myGrids.Add (t_grid); //Add it to the list
                    t_grid.transform.SetParent (this.transform); //Set the parent to this gameObject
                    t_grid.name = myGridPrefab.name + "(" + i + ")(" + j + ")"; //Name it
                }
            }
        }
    }
}


[Unity] Collision action matrix

https://docs.unity3d.com/Manual/CollidersOverview.html

When two objects collide, a number of different script events can occur depending on the configurations of the colliding objects’ rigidbodies. The charts below give details of which event functions are called based on the components that are attached to the objects. Some of the combinations only cause one of the two objects to be affected by the collision, but the general rule is that physics will not be applied to an object that doesn’t have a Rigidbody component attached.

Collision detection occurs and messages are sent upon collision
Static Collider Rigidbody Collider Kinematic Rigidbody Collider Static Trigger Collider Rigidbody Trigger Collider Kinematic Rigidbody Trigger Collider
Static Collider Y
Rigidbody Collider Y Y Y
Kinematic Rigidbody Collider Y
Static Trigger Collider
Rigidbody Trigger Collider
Kinematic Rigidbody Trigger Collider
Trigger messages are sent upon collision
Static Collider Rigidbody Collider Kinematic Rigidbody Collider Static Trigger Collider Rigidbody Trigger Collider Kinematic Rigidbody Trigger Collider
Static Collider Y Y
Rigidbody Collider Y Y Y
Kinematic Rigidbody Collider Y Y Y
Static Trigger Collider Y Y Y Y
Rigidbody Trigger Collider Y Y Y Y Y Y
Kinematic Rigidbody Trigger Collider Y Y Y Y Y Y