Hello all, I’ve been stuck for a few days on how to add a script to a child, I have searched a lot on this forum and StackOverflow and couldn’t find a clear answer to my question.
(For context, my project will load a OBJ from a path, and when I activate the parent script (AddScript.cs), it’ll add the script (AddBoxCollider.cs) to the parent created OBJ, and (AddBoxCollider.cs) will add a Box Collider to every individual child.)
I’ve tried to use Types to no avail.
Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AddScript : MonoBehaviour
{
void Start()
{
var allDescendents = GetComponentsInChildren();
foreach (var t in allDescendents)
{
t.AddComponent();
}
}
}
Error:
(Ignore the OBJImport samples)
I’ve been trying to figure this out for two days now, any help would be greatly appreciated ![]()
