Add the script to the object from another script.

Hi. I want that my script add another script to another object but it doesn’t work.
Could you check it. (Sorry for my spelling, I do not know English very well) :slight_smile:

using UnityEngine;

using System.Collections;

public class Enter : MonoBehaviour {

public GameObject obiekt2;

void OnTriggerEnter(Collider samochod){

	if( == "cube" ){


If you are trying to add a script component, use AddComponent. GetComponent only gives access to an existing component.