Unity 5 OnCollisionEnter IF statement not working.

Help… what’s wrong with my script!!! im just trying to make a script that when the player collides with a cube or trigger it will start a function of if statement but never happens here’s my script… I will appreciate who answer this thank you LOVE UNITY!!!

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class scriptB : MonoBehaviour {

public GameObject cube1;
public GameObject parent;
public Button pickUpAndPlace;
public Button place;

void OnCollisionEnter (Collision col) {
	
	if(col.gameObject.name == "trigger2") {
		
		test();

	}
	if(Input.GetKeyDown("space")) {

		print("Hello World");

	}

}

void test () {

	cube1.transform.parent = parent.transform;

}

}

hi
if u want to use a "Input.GetKeyDown() " function u should use it in TriggerStay like this :

  void OnCollisionStay(Collision col)
    {
 
        if (Input.GetKeyDown(KeyCode.Space))
        {
            print("Hello World");
        }
    }

and for this u better use trigger and not Collision:

void OnTriggerStay(Collider col)
{

    if (Input.GetKeyDown(KeyCode.Space))
    {
        print("Hello World");
    }
}