本文整理汇总了C#中MonoBehaviour.GetComponent方法的典型用法代码示例。如果您正苦于以下问题:C# MonoBehaviour.GetComponent方法的具体用法?C# MonoBehaviour.GetComponent怎么用?C# MonoBehaviour.GetComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MonoBehaviour
的用法示例。
在下文中一共展示了MonoBehaviour.GetComponent方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RegisterUnknownObject
// Called by OnNetworkInstantiate
public void RegisterUnknownObject( MonoBehaviour _obj )
{
if ( _obj.GetComponent<NetworkView>() == null )
{
DebugConsole.Warning( "Cannot add NetworkOwnerControl without a NetworkView (" + _obj.gameObject.name + ")", _obj );
return;
}
NetworkView view = _obj.GetComponent<NetworkView>();
NetworkViewID id = view.viewID;
if ( this.map.ContainsKey( _obj.GetComponent<NetworkView>().viewID ) )
{
DebugConsole.Warning( "NetworkViewID " + id + " aleady exists as " + _obj.gameObject.name,
this.map[id].gameObject );
DebugConsole.Warning( "Cannot set " + id + " to " + _obj.gameObject.name, _obj.gameObject );
return;
}
if ( view.isMine ) // If it is mine, tell everyone else about it
{
int ownerID = Common.MyNetworkID();
GameNetworkManager.instance.SendSetViewIDMessage( ownerID, id );
_obj.GetComponent<NetworkOwnerControl>().ownerID = ownerID;
}
else // If it isn't mine, store this away and wait for the RPC
{
this.map.Add( id, view );
#if UNITY_EDITOR
this.debugList.Add( view );
#endif
}
}
示例2: WaitForAnimationState
public WaitForAnimationState(MonoBehaviour animatorSibling, string stateName)
{
//Debug.LogError("WaitForAnimationState CTOR");
animator = animatorSibling.GetComponent<Animator>();
this.stateName = stateName;
this.stateHash = Animator.StringToHash(stateName);
}
示例3: Init
public void Init(MonoBehaviour parent)
{
this.parent = parent;
parentRB = parent.GetComponent<Rigidbody2D> ();
forward = false;
rightMove = false;
leftMove = false;
lastMoveVector = parent.transform.up;
}
示例4: AIBaseState
public AIBaseState(MonoBehaviour p)
{
parent = p;
agent = parent.GetComponent<NavMeshAgent>();
selectExecutor = new SelectTargetExecutor();
selectExecutor.Init(this);
moveExecutor = new MoveActionExecutor();
moveExecutor.Init(this);
lookatExecutor = new LookatActionExecutor();
lookatExecutor.Init(this);
}
示例5: MicIn
public MicIn(MonoBehaviour _parent, float _sensitivity)
{
sensitivity = _sensitivity;
parent = _parent;
loudness = 0;
parent.GetComponent<AudioSource>().clip = Microphone.Start(null, true, 1, 48000);
parent.GetComponent<AudioSource>().loop = false; // Set the AudioClip to loop
parent.GetComponent<AudioSource>().mute = false; // Mute the sound, we don't want the player to hear it
parent.GetComponent<AudioSource>().bypassEffects = true;
parent.GetComponent<AudioSource>().bypassReverbZones = true; //also important, remmoves reverb so no feedback loops
parent.GetComponent<AudioSource>().spatialBlend = 0.0f;
parent.GetComponent<AudioSource>().reverbZoneMix = 0.0f;
while (!(Microphone.GetPosition(null) > 0)) { } //this seems to fix the latency issue. i know its bad code, fuck off.
parent.GetComponent<AudioSource>().Play(); //play the audio source!
parent.InvokeRepeating("PlayAudioSource", 1.0f, 1.0f);
}
示例6: BindSimpleField
/// <summary>
/// Initializes the specified field of component given then information in bindAttribute.
/// </summary>
/// <param name="field">Field to bind</param>
/// <param name="bindAttribute">Information about how to bind it</param>
/// <param name="component">Object with the field</param>
private static void BindSimpleField(FieldInfo field, BindAttribute bindAttribute, MonoBehaviour component)
{
Object target = null;
switch (bindAttribute.Scope)
{
case BindingScope.GameObject:
target = component.GetComponent(field.FieldType);
break;
case BindingScope.GameObjectOrChildren:
target = component.GetComponentInChildren(field.FieldType);
break;
case BindingScope.Global:
target = FindObjectOfType(field.FieldType);
break;
}
if (target == null)
switch (bindAttribute.IfNotFound)
{
case BindingDefault.Exception:
throw new Exception("No target to bind to");
case BindingDefault.Create:
target = component.gameObject.AddComponent(field.FieldType);
break;
case BindingDefault.Ignore:
break;
}
field.SetValue(component, target);
}
示例7: getVerticesContour
// Считывание вершин MeshFilter-а в контур кватернионов с корректировкой значений (если требуется)
List<Quaternion> getVerticesContour(MonoBehaviour gameObject, Vector3 correctionVect = new Vector3())
{
MeshFilter viewedModelFilter = (MeshFilter)gameObject.GetComponent("MeshFilter");
Mesh viewedModel = viewedModelFilter.mesh;
Vector3[] vertices = viewedModel.vertices;
List<Quaternion> contour = new List<Quaternion> ();
for (int i = 0; i < vertices.Length; ++i) {
Vector3 vertex = gameObject.transform.TransformPoint(vertices[i]);
Quaternion quaternion = new Quaternion(vertex.x + correctionVect.x,
vertex.y + correctionVect.y,
vertex.z + correctionVect.z,
0.0f);
contour.Add(quaternion);
}
return contour;
}
示例8: bossDefeated
public void bossDefeated(MonoBehaviour bossObject)
{
Destroy(bossObject.GetComponent("EnemyMover_Boss"));
Application.LoadLevel(0);
}
示例9: GetToBeInjectedObject
public UnityEngine.Object GetToBeInjectedObject(MonoBehaviour target)
{
return target.GetComponent(ComponentType.Name);
}
示例10: EnableBehaviorAfterTime
/// <summary>
/// Enables behavior after some time.
/// </summary>
private IEnumerator EnableBehaviorAfterTime(MonoBehaviour b, float time)
{
// wait
yield return new WaitForSeconds(time);
// check
if (b)
// enable if not picked
if (!b.GetComponent<Pickable>().Picked)
b.enabled = true;
}
示例11: moveButtonTo
private void moveButtonTo(MonoBehaviour button, Hexagon hexagon, Vector3 offset)
{
var rectTransform = button.GetComponent<RectTransform>();
if (hexagon != null && !(userInteractionState == UserInteractionState.StartedDragging || userInteractionState == UserInteractionState.StartedMoving))
{
var screenPoint = Camera.main.WorldToScreenPoint(hexagon.transform.position);
rectTransform.transform.position = screenPoint + offset;
rectTransform.localScale = new Vector3(1, 1, 1);
}
else
{
rectTransform.localScale = new Vector3(0, 0, 0);
}
}