Quantcast
Channel: Answers for "Dynamic AddComponent?"
Viewing all articles
Browse latest Browse all 6

Answer by _Gkxd

$
0
0
Instead of storing the names of the classes, you can just store the list of components: Include this line at the top of your script using System.Collections.Generic; Somewhere inside the class List componentsToAdd; // Your list of components void Start() { componentsToAdd = new List(); componentsToAdd.add(/* some component */); // Repeat as necessary } When you want to add components foreach (Component c in componentsToAdd) { someGameObject.AddComponent(c.GetType()); }

Viewing all articles
Browse latest Browse all 6

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>