How to give a component on collision?

using UnityEngine;
using System.Collections;

public class finish : MonoBehaviour {

	void OnCollisionEnter (Collision col)
	{
		if(col.gameObject.name == "DeathCube1")
		{

		gameObject.AddComponent (Ctrl2);

		}

	}
	}

Im trying to add my script Ctrl2 when deathcube1 touches this object

This script will attach Ctrl2 to the GamObject with OnCOllisionEnter script. Are u trying to attach Ctrl2 to DeathCube1? then use col.gameObject.AddComponent (Ctrl2);

col.gameObject.AddComponent<Ctrl2>();

1 Answer

1

col.gameObject.AddComponent<Ctrl2>();

Converted this to an answer as it is a valid answer, and correct.