当前位置: 首页>>代码示例>>C#>>正文


C# Component.GetComponent方法代码示例

本文整理汇总了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;
    }
开发者ID:Jahoe,项目名称:Blocks,代码行数:14,代码来源:Game.cs

示例2: AddHealth

 public static void AddHealth(Component entity, int health)
 {
     HealthHandler handler = entity.GetComponent<HealthHandler>();
     if (handler) {
         handler.AddHealth(health);
     }
 }
开发者ID:JimWest,项目名称:UnityTestProject,代码行数:7,代码来源:HealthUtility.cs

示例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;
 }
开发者ID:tomasmed,项目名称:AmazonWarriors,代码行数:7,代码来源:UIShowHideController.cs

示例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;
 }
开发者ID:Miista,项目名称:TerrainGeneration,代码行数:8,代码来源:AiRig.cs

示例5: DeductHealth

 public static bool DeductHealth(Component entity, int health)
 {
     HealthHandler handler = entity.GetComponent<HealthHandler>();
     if (handler) {
         return handler.DeductHealth(health);
     }
     return false;
 }
开发者ID:JimWest,项目名称:UnityTestProject,代码行数:8,代码来源:HealthUtility.cs

示例6: DamageWall

 void IInteractable.Interact(Component sender)
 {
     var damager = sender.GetComponent<IWallDamage>();
     if (damager != null)
     {
         DamageWall(damager.GetWallDamage());
     }
 }
开发者ID:EimantasSapoka,项目名称:Game_hobby,代码行数:8,代码来源:Wall.cs

示例7: AddLink

 public void AddLink(Component obj)
 {
     if (IsFull) return;
     if (links == null) {
         links = new Rigidbody[4];
     }
     links[linkCount++] = obj.GetComponent<Rigidbody>();
 }
开发者ID:m4c0,项目名称:ludum-dare-23,代码行数:8,代码来源:AtomicLink.cs

示例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;
 }
开发者ID:davidMa88,项目名称:shotemup_repo,代码行数:8,代码来源:Cooltimer.cs

示例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;
        }
开发者ID:Raj2509,项目名称:net.kibotu.sandbox.unity.dragnslay,代码行数:10,代码来源:init.cs

示例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);
 }
开发者ID:Phelisse,项目名称:Elynium,代码行数:10,代码来源:menu2option.cs

示例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);
         }
     }
 }
开发者ID:HiroLord,项目名称:VGDesign,代码行数:10,代码来源:GeyserDamageScript.cs

示例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);
		}
开发者ID:JuanJosePol,项目名称:ggjmallorca2016,代码行数:10,代码来源:EffectsPostProcessor.cs

示例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);
    }
开发者ID:silenthunter,项目名称:ColonyBuilder,代码行数:55,代码来源:MouseManager.cs

示例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);
    }
开发者ID:taimic,项目名称:Herbert_Prototype,代码行数:15,代码来源:Ship.cs

示例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();
    }
开发者ID:GooTechnologies,项目名称:CreateUnityExporter,代码行数:15,代码来源:GLexMaterial.cs


注:本文中的UnityEngine.Component.GetComponent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。