- Home /
Question by
VRCP · Jul 13, 2016 at 09:16 AM ·
c#scripting problemeditor-scripting
Editor Scripting - Add Component if certain Tag is selected
Hi, I want to simpilfy my life by using editor scripts.
If I select a certain Tag for a GameObject in the Editor I want a component to be automatically added to this GameObject. I don't know how to trigger this.
Is there a function called something like "OnTagChange"?
Here is what I got so far. Obvisiously it doesn't work ;)
using UnityEngine;
using System.Collections;
using UnityEditor;
public class AddComponent: MonoBehaviour
{
void OnTagChange()
{
CreateNetworkView(GameObject.FindGameObjectsWithTag("Dynamic"));
}
private void CreateNetworkView(GameObject[] objs)
{
foreach (GameObject dynamic in objs)
{
NetworkView nView = dynamic.AddComponent<NetworkView>() as NetworkView;
dynamic.GetComponent<NetworkView>().observed = dynamic.transform;
dynamic.GetComponent<NetworkView>().stateSynchronization = NetworkStateSynchronization.ReliableDeltaCompressed;
dynamic.GetComponent<NetworkView>().viewID = Network.AllocateViewID();
}
}
}
Thanks.
Comment
Your answer
Follow this Question
Related Questions
Is it possible to write a function in the backend of an editor script for a scriptableObject? 0 Answers
Multiple Cars not working 1 Answer
Custom Grid Object Always Starts at 0,0 of editor window. 0 Answers
Distribute terrain in zones 3 Answers
Confused about custom GameObjects,Custom GameObject confusion 0 Answers