c# - Get the script name from game object -


i have gameobject 2 scripts attached it. want name of second script first script. remember:

  1. i don't want direct assignment (i know well).
  2. first script name can not hard coded causes change.

consequently, want script name , set script property ?

i not sure mean "i want name of second script first script", take @ this:

enter image description here

i have scripts attached main camera gameobject.

here code of test.cs:

using unityengine; using system.collections;  public class test : monobehaviour  {      void start()     {         monobehaviour[] scripts = this.getcomponents<monobehaviour> ();          foreach (monobehaviour mb in scripts)         {             debug.log (mb.gettype ().name);         }     } } 

on start prints names of monobehaviours on it:

enter image description here


Comments