- Home /
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) :)
using UnityEngine;
using System.Collections;
public class Enter : MonoBehaviour {
public GameObject obiekt2;
void OnTriggerEnter(Collider samochod){
if(samochod.name == "cube" ){
obiekt2.gameObject.GetComponent<skrypt>();
Debug.Log("text");
}
}
}
Thanks. It works. But if I wanted to add script JS (skrypt.js) from within C #, what I would have done?
I'm not exactly sure what you mean by adding a script from within C#, can u elaborate?
Answer by fighder · May 10, 2015 at 07:20 PM
If you are trying to add a script component, use AddComponent. GetComponent only gives access to an existing component.
obiekt2.gameObject.AddComponent();
Your answer
Follow this Question
Related Questions
Terrain collider - add 2 Answers
Create a game objective. 2 Answers
Adding a life on collision, otherwise subtract 1 Answer
C# Adding Multiple Elements to a List on One Line 5 Answers
Adding tools with respect to points 1 Answer