本文整理汇总了C#中UnityEngine.Component.GetComponent方法的典型用法代码示例。如果您正苦于以下问题:C# Component.GetComponent方法的具体用法?C# Component.GetComponent怎么用?C# Component.GetComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Component
的用法示例。
在下文中一共展示了Component.GetComponent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BlockSelectionFail
/// <summary>
/// Called when the block swap fails due to specified reason.
/// </summary>
/// <param name="block">Second block. First block is pulled from memory</param>
private void BlockSelectionFail(Component block)
{
block.GetComponent<Block>().Selected = false;
_swap.GridBlocks[_blockMemoryInt].GetComponent<Block>().Selected = false;
block.GetComponent<Block>().AudioFail();
_blockMemoryInt = -1;
BlockSelectedCount = 0;
}
示例2: AddHealth
public static void AddHealth(Component entity, int health)
{
HealthHandler handler = entity.GetComponent<HealthHandler>();
if (handler) {
handler.AddHealth(health);
}
}
示例3: UIShowHideController
public UIShowHideController(GameObject go, Component panel)
{
this.panel = panel;
this.animator = (go != null) ? go.GetComponent<Animator>() : null;
if (animator == null && panel != null) animator = panel.GetComponent<Animator>();
this.animCoroutine = null;
}
示例4: ExtractRigInfo
//Should only be created as part of our base framework
public static AiRig ExtractRigInfo(Component c)
{
var rig = c.GetComponent<AiRig>();
if (rig == null)
c.GetComponentInParent<AiRig>();
return rig;
}
示例5: DeductHealth
public static bool DeductHealth(Component entity, int health)
{
HealthHandler handler = entity.GetComponent<HealthHandler>();
if (handler) {
return handler.DeductHealth(health);
}
return false;
}
示例6: DamageWall
void IInteractable.Interact(Component sender)
{
var damager = sender.GetComponent<IWallDamage>();
if (damager != null)
{
DamageWall(damager.GetWallDamage());
}
}
示例7: AddLink
public void AddLink(Component obj)
{
if (IsFull) return;
if (links == null) {
links = new Rigidbody[4];
}
links[linkCount++] = obj.GetComponent<Rigidbody>();
}
示例8: Set
public static Cooltimer Set(Component component, float cooltime, Action onFinished)
{
var cooltimer = component.GetComponent<Cooltimer>();
if (cooltimer == null) cooltimer = component.gameObject.AddComponent<Cooltimer>();
cooltimer.cooltime = cooltime;
cooltimer.onFinished = onFinished;
return cooltimer;
}
示例9: MovePlane
private static IEnumerator MovePlane(Component plane, GameObject target)
{
if (plane == null) throw new ArgumentNullException("plane");
var rotation = plane.GetComponent<Orbiting>();
Destroy(rotation);
var move = plane.gameObject.AddComponent<MoveToTarget>();
move.Target = target;
yield return 0;
}
示例10: menu2option_
public void menu2option_(Component menu)
{
//RectTransform RT = menu_option.GetComponent<RectTransform>();
Animator A = menu.GetComponent<Animator>();
A.SetBool("IsOpen", true);
GetComponent<Animator>().SetBool("IsOpen", false);
//GetComponent("Menu").GetComponent<CanvasGroup>().alpha = 0;
//GetComponent("Menu").GetComponent<RectTransform>().position = new Vector3(0,370,0);
//RT.position = new Vector3(0, 370, 0);
}
示例11: OnTriggerEnter
void OnTriggerEnter(Component other)
{
if (other.name.Equals ("Player")) {
Player player = other.GetComponent<Player>();
if(player != null){
print ("Geyser burn");
player.currentHealth -= (int) (player.startingHealth * .10);
}
}
}
示例12: ProcessDepthOfField
private static void ProcessDepthOfField(Component gameComponent, Component sceneComponent)
{
Type dofType = sceneComponent.GetType();
FieldInfo fPlaneField = dofType.GetField("focusPlane", Utilities.DEFAULT_BINDING_FLAG);
if (fPlaneField == null) return;
float currentValue = (float)fPlaneField.GetValue(sceneComponent);
float factor = Mathf.Pow(Mathf.Pow(currentValue, 4) / (sceneComponent.GetComponent<Camera>().farClipPlane / gameComponent.GetComponent<Camera>().farClipPlane), 1.0f / 4);
fPlaneField.SetValue(sceneComponent, factor);
}
示例13: Update
// Update is called once per frame
void Update()
{
//Finds the point on the ground that is being moused over
Ray camPoint = Camera.mainCamera.ScreenPointToRay(Input.mousePosition);
RaycastHit hitInfo;
bool overGround = Physics.Raycast(camPoint, out hitInfo, Mathf.Infinity, GlobalConstants.GROUND_MASK);//Mask to hit only the ground
Debug.DrawRay(camPoint.origin, camPoint.direction * 100, overGround ? Color.green : Color.red);
//The mouse isn't over the map
if(!overGround) return;
//Computer what tile that point is in
OverTile.x = (int)(hitInfo.point.x / GlobalConstants.TileSize);
OverTile.y = (int)(hitInfo.point.z / GlobalConstants.TileSize);
if(GuiManager.InBuildMode)
{
if(HoverObject != null) HoverObject.gameObject.active = false;
HoverObject = GuiManager.GetSelectedComponent();
HoverObject.gameObject.active = true;
Vector2 structSize = ((Structure)HoverObject.GetComponent("Structure")).Size;
HoverObject.transform.position = new Vector3(OverTile.x, 0f, OverTile.y) * GlobalConstants.TileSize
+ new Vector3(GlobalConstants.TileSize, 0, GlobalConstants.TileSize) / 2;
}
else
if(HoverObject != null)
HoverObject.transform.position = new Vector3(-100, -100, -100);
Debug.Log(hitInfo.point);
if(Input.GetMouseButtonDown(0) && !lastMouse && overGround && GuiManager.SelectedStructure != null)
{
//Don't overwrite a structure
if(WorldManager.GetStructureAt((int)OverTile.x, (int)OverTile.y) == null)
{
//Make sure the placement is valid
if(WorldManager.isValidPlacement(GuiManager.SelectedStructure, (int)OverTile.x, (int)OverTile.y))
{
Component newStructure = (Component)Instantiate(GuiManager.SelectedStructure);
Vector2 structSize = ((Structure)newStructure.GetComponent("Structure")).Size;
newStructure.transform.position = new Vector3(OverTile.x, 0f, OverTile.y) * GlobalConstants.TileSize
+ new Vector3(GlobalConstants.TileSize, 0, GlobalConstants.TileSize) / 2;
//TODO: Do this smoother. Create and destroy seems inefficient
WorldManager.AddStructure(newStructure, (int)OverTile.x, (int)OverTile.y);
}
}
}
lastMouse = Input.GetMouseButtonDown(0);
}
示例14: AddComponent
public void AddComponent(Component component)
{
Rigidbody2D rb = component.GetComponent<Rigidbody2D>();
FixedJoint2D newJoint = gameObject.AddComponent<FixedJoint2D>();
//RelativeJoint2D newJoint = gameObject.AddComponent<RelativeJoint2D>();
newJoint.connectedBody = rb;
if (components == null)
components = new List<Component>();
components.Add(component);
component.Ship = this;
transform.position = GetCenter();
//print("woop " + component.GetInstanceID() + " #:" + components.Count);
}
示例15: GLexMaterial
public GLexMaterial(Material material, Component meshRenderer)
{
mMaterial = material;
mMaterialSettings = meshRenderer.GetComponent<GLexMaterialSettings>();
mUniqueName = mMaterial.name;
while (UniqueNameExists( mUniqueName )) {
mUniqueName = mMaterial.name + (mUniqueId++).ToString();
}
mMaterials.Add(this);
AddTextures();
AddShader();
}