- Home /
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);
Answer by Inaetaru · Aug 23, 2015 at 06:45 PM
col.gameObject.AddComponent<Ctrl2>();
Converted this to an answer as it is a valid answer, and correct.
Your answer
![](https://koobas.hobune.stream/wayback/20220612000950im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Get Object that Instantiated this object 1 Answer
My marble (Player/Gameobject) goes through the "play board" (gameobject). Why? 1 Answer
How to only delete one of two collided objects? 1 Answer
Gameobject collision with Terrain C# 4 Answers
Can Someone Help Me With Changing Material / Texture On Collision Event 1 Answer