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


C# GameObject.GetComponent方法代码示例

本文整理汇总了C#中UnityEngine.GameObject.GetComponent方法的典型用法代码示例。如果您正苦于以下问题:C# GameObject.GetComponent方法的具体用法?C# GameObject.GetComponent怎么用?C# GameObject.GetComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UnityEngine.GameObject的用法示例。


在下文中一共展示了GameObject.GetComponent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnGUI

 void OnGUI()
 {
     GUILayout.Box("Legacy Effect Scale Editor", GUILayout.Width(295));
     EditorGUILayout.Space();
     Effect = (GameObject)EditorGUILayout.ObjectField("Legacy Effect", Effect, typeof(GameObject), true); 
     EditorGUILayout.Space();
     EditorGUILayout.Space();
     EditorGUILayout.Space();
     EditorGUILayout.Space();
     Scale = float.Parse(EditorGUILayout.TextField("Scale Change Value", Scale.ToString()));
     EditorGUILayout.Space();
     EditorGUILayout.Space();
     EditorGUILayout.Space();
     EditorGUILayout.Space();
     if (GUILayout.Button("Scale Apply", GUILayout.Height(70))) 
     {
         if (Effect.GetComponent<csLegacyEffectChanger>() != null)
             Effect.GetComponent<csLegacyEffectChanger>().LegacyEffectScaleChange(Scale);
         else
         {
             Effect.AddComponent<csLegacyEffectChanger>();
             Effect.GetComponent<csLegacyEffectChanger>().LegacyEffectScaleChange(Scale);
         }
         DestroyImmediate(Effect.GetComponent<csLegacyEffectChanger>());
     }
 }
开发者ID:hydrater,项目名称:Lucid,代码行数:26,代码来源:csLegacyEffectEditor.cs

示例2: OnMouseDown

 public void OnMouseDown()
 {
     //pego a unidade selecionada atravez do controlador de jogo
     GameObject selecionado = gameObject.transform.parent.parent.parent.GetComponent<ControladorDeJogo>().objetoSelecionado;
     //Se tiver algum objeto selecionado, mando a unidade selecionada se mover para o objeto clicado
     if(selecionado != null)
     {//Se tiver alguma unidade selecionada
         if(tropaJogador == null)
         {//E se nao tiver nem uma unidade nesse alvo (unidade do jogador)
             //Defino que tem uma unidade vindo pra ca
             tropaJogador = selecionado;
             //Se a unidade que esta vindo estiver vindo de um outro alvo, limpo o alvo antigo
             if(tropaJogador.GetComponent<ComportamentoDeUnidade>().alvoAtual != null)
                 tropaJogador.GetComponent<ComportamentoDeUnidade>().alvoAtual.GetComponent<AcoesJogadorAlvo>().tropaJogador = null;
             //Mando a unidade se mover para o alvo atual
             tropaJogador.GetComponent<ComportamentoDeUnidade>().moverSoldados(gameObject);
             //E digo que esse alvo e o novo destino dele
             tropaJogador.GetComponent<ComportamentoDeUnidade>().alvoAtual = gameObject;
             //atualizar as cores do alvo
             atualizarCores();
         }
         else
             gameObject.transform.parent.parent.parent.GetComponent<ControladorDeJogo>().hud.GetComponent<ControladorDeInterface>().escreverMensagem("Nao pode haver dois grupos em um mesmo alvo");
     }
 }
开发者ID:Marcos1994,项目名称:Luria,代码行数:25,代码来源:AcoesJogadorAlvo.cs

示例3: Move

 private void Move(GameObject prefab)
 {
     //move object upwards over time * speed
     Vector2 pos = prefab.GetComponent<RectTransform>().anchoredPosition;
     pos.y += 1 * speed * Time.deltaTime;
     prefab.GetComponent<RectTransform>().anchoredPosition = pos;
 }
开发者ID:kayetea,项目名称:EntertainmentApp,代码行数:7,代码来源:LoopImageStack.cs

示例4: Start

 void Start()
 {
     levelClock = GameObject.Find("gameBase").GetComponent<levelClock>();
     spaceship = GameObject.Find("spaceship");
     rb = spaceship.GetComponent<Rigidbody2D>();
     body = spaceship.GetComponent<Transform>();
 }
开发者ID:CalebOuellette,项目名称:planetPlanner,代码行数:7,代码来源:keyBoardScript.cs

示例5: Fire

 void Fire()
 {
     // 프리팹 동적 생성
     target_projectile = (GameObject)Instantiate(projectile, new Vector3(firePos.x,firePos.y), fireAngle);
     target_projectile.GetComponent<BazookaCtrl>().globalId = GetComponentInParent<NetPlayerCtrl>().globalId;
     target_projectile.GetComponent<BazookaCtrl>().shotPower = fireForce;
 }
开发者ID:lastone9182,项目名称:NetworkProgramming,代码行数:7,代码来源:NetFireCtrl.cs

示例6: Update

    // Update is called once per frame
    void Update()
    {
        timerText = GameObject.Find("dynamic timer text");
        monster = GameObject.Find("Player");
        timer += Time.deltaTime;
        gameOver += Time.deltaTime;

        if (timer > 1.0f)
        {
            transform.Rotate((float)180/levelTime, 0.0f, 0.0f);
            timer = 0.0f;
        }

        if (levelTime - gameOver >= 0)
        {
            timerText.GetComponent<Timer>().timer = levelTime - gameOver;
        }

        if (gameOver > levelTime && GameObject.Find("Plant") != null)
        {
            //gameOverText.active = true;
            nextLevelBut.transform.Translate(1,0,0);
            gameOverText.GetComponent<GUIText>().text = "You Survived The Day Victory Is Yours!";
            monster.GetComponent<AIFollow>().Stop();
            if (monster.GetComponent<AIFollow>().speed <= 0)
            {
                Destroy(monster);
            }
            gameOver = 0.0f;
        }
    }
开发者ID:PileOfFish,项目名称:PileOfFishProductions,代码行数:32,代码来源:Timer_Cycle.cs

示例7: AddClusterScripts

    void AddClusterScripts(GameObject iObject, bool iChildren)
    {
        //MiddleVRTools.Log("AddCluster to " + iObject);
        //print("AddCluster to " + iObject);
        {
            if (iObject.GetComponent<VRShareTransform>() == null)
            {
                VRShareTransform script = iObject.AddComponent<VRShareTransform>() as VRShareTransform;
                script.Start();
            }

            if (iObject.GetComponent<VRApplySharedTransform>() == null)
            {
                VRApplySharedTransform script = iObject.AddComponent<VRApplySharedTransform>() as VRApplySharedTransform;
                script.Start();
            }
        }

        if( iChildren == true )
        {
            foreach (Transform child in iObject.transform)
            {
                GameObject childObject = child.gameObject;

                //print("Child : " + childObject);
                AddClusterScripts(childObject, true);
            }
        }
    }
开发者ID:PixelSenseEnib,项目名称:PixelSense,代码行数:29,代码来源:VRClusterObject.cs

示例8: Update

    void Update()
    {
        if (ritualStart)
        {
            GetComponent<EllipsoidParticleEmitter>().emit = true;
            GetComponent<ParticleAnimator>().damping = timeAndDumbing;
            timeAndDumbing += 0.01f;

            if (isTriggered & !isCreated)
            {
                GetComponent<EllipsoidParticleEmitter>().emit = true;
               enemy = Instantiate(enemyPrefab, transform.position, Quaternion.identity) as GameObject;
                monkGroup.GetComponent<InputHandler>().enemy = enemy;
                enemy.GetComponent<Enemy>().canvasPlane = plane;
                enemy.GetComponent<Enemy>().canvasText = text;
                isCreated = true;
                monkGroup.GetComponent<GroupMovement>().StopMovement();
            }

            if (timeAndDumbing >= 1)
            {
                GetComponent<EllipsoidParticleEmitter>().emit = false;
                enemy.GetComponent<EnemyMovement>().StartMovement();
                monkGroup.GetComponent<GroupMovement>().StartMovement();
                monkGroup.GetComponent<GroupMovement>().movementSpeed = 5.0f;
                Destroy(this.gameObject, 2.0f);
            }
        }
    }
开发者ID:VladimirMakeev,项目名称:WanderingMonks,代码行数:29,代码来源:Ritual.cs

示例9: PlaySounds

    public static void PlaySounds(GameObject obj, AudioClip[] clips)
    {
        if(clips == null || clips.Length == 0) return;

        obj.GetComponent<AudioSource>().clip = clips[Random.Range(0, clips.Length)];
        obj.GetComponent<AudioSource>().Play();
    }
开发者ID:alexidr,项目名称:LD33,代码行数:7,代码来源:Sounds.cs

示例10: CreateDecal

        public static GameObject CreateDecal(Material mat, Rect uvCoords, float scale)
        {
            GameObject decal = new GameObject();
            decal.name = "Decal" + decal.GetInstanceID();

            decal.AddComponent<MeshFilter>().sharedMesh = DecalMesh("DecalMesh" + decal.GetInstanceID(), mat, uvCoords, scale);
            decal.AddComponent<MeshRenderer>().sharedMaterial = mat;

            #if UNITY_5
            decal.GetComponent<MeshRenderer>().shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
            #else
            decal.GetComponent<MeshRenderer>().castShadows = false;
            #endif

            qd_Decal decalComponent = decal.AddComponent<qd_Decal>();

            decalComponent.SetScale(scale);
            decalComponent.SetTexture( (Texture2D)mat.mainTexture );
            decalComponent.SetUVRect(uvCoords);

            #if DEBUG
            decal.AddComponent<qd_DecalDebug>();
            #endif

            return decal;
        }
开发者ID:zjucsxxd,项目名称:UnityRepository,代码行数:26,代码来源:qd_Mesh.cs

示例11: PlayerDeath

    IEnumerator PlayerDeath(GameObject temp)
    {
        //player.GetComponent<PlatformerAnimation>().PlayerDied();
        temp = this.player;

        if(temp.name=="Player"){
        temp.GetComponent<PlayerController>().RemoveControl();
        AudioSource.PlayClipAtPoint(deathSound, temp.transform.position);
        yield return new WaitForSeconds(2.0f);
        temp.GetComponent<PlayerPhysics>().Reset();
        //player.GetComponent<PlatformerAnimation>().PlayerLives();

        temp.GetComponent<PlayerController>().GiveControl();
        }

        else {
            BoxController control = temp.GetComponent<BoxController>();

            if(control.velCheck()){
            AudioSource.PlayClipAtPoint(boxPop, temp.transform.position);
            //yield return new WaitForSeconds(2.0f);
                temp.GetComponent<PlayerPhysics>().Reset();
            }
        }
    }
开发者ID:Joon-min,项目名称:Serious_game,代码行数:25,代码来源:DeathZone.cs

示例12: Start

 // Use this for initialization
 void Start()
 {
     rend = GetComponent<Renderer>();
     pl = GameObject.FindGameObjectWithTag("Player");
     Physics2D.IgnoreCollision(GetComponent<Collider2D>(), pl.GetComponent<Collider2D>());
     Physics2D.IgnoreCollision(GetComponent<Collider2D>(), pl.GetComponent<CircleCollider2D>());
 }
开发者ID:crazymeeshu,项目名称:scriptcaster,代码行数:8,代码来源:spout.cs

示例13: Create

    public static Bone Create() {
        GameObject b = new GameObject("Bone");
        Undo.RegisterCreatedObjectUndo(b, "Add child bone");
        b.AddComponent<Bone>();

        if (Selection.activeGameObject != null) {
            GameObject sel = Selection.activeGameObject;
            b.transform.parent = sel.transform;

            if (sel.GetComponent<Bone>() != null) {
                Bone p = sel.GetComponent<Bone>();
                b.transform.position = p.Head;
                b.transform.localRotation = Quaternion.Euler(0, 0, 0);
            }
        }

        Skeleton skel = b.transform.root.GetComponentInChildren<Skeleton>();

        if (skel != null) {
            Bone[] bones = skel.GetComponentsInChildren<Bone>();
            int index = bones.Max(bn => bn.index) + 1;
            b.GetComponent<Bone>().index = index;
            skel.CalculateWeights();
        }

        Selection.activeGameObject = b;

        return b.GetComponent<Bone>();
    }
开发者ID:chimchim,项目名称:Chilenska,代码行数:29,代码来源:Bone.cs

示例14: respawnCharacter

        private static EffectStop respawnCharacter(GameObject character)
        {
            return () =>
            {
                var manager = GameObject.Find("GameManager").GetComponent<GameManager>();
                var combatData = character.GetComponent<Combat>();
                var characterData = character.GetComponent<Character>();

                // Consider character to be alive
                combatData.dead = false;
                combatData.selectable = true;

                // Restore health
                combatData.health = combatData.maxHealth;
                combatData.mana = combatData.maxMana();

                // Move Character to correct position
                var spawn = character.tag == "TeamA" ?
                        manager.bluespawn[UnityEngine.Random.Range(0, manager.bluespawn.Length)] :
                        manager.redspawn[UnityEngine.Random.Range(0, manager.redspawn.Length)];
                character.transform.position = spawn.transform.position;

                // Set animation state to alive
                characterData.setAnimation_State(characterData.dead_State, false);

                // Enable movement
                character.GetComponent<NavMeshAgent>().enabled = true;
                character.GetComponent<Rigidbody>().useGravity = true;
            };
        }
开发者ID:JD95,项目名称:Factionless,代码行数:30,代码来源:CharacterState_Manager.cs

示例15: SetAttacker

 public void SetAttacker(GameObject g)
 {
     attacker = g;
     if (attacker.gameObject.tag == "Player")
     {
         direction = attacker.GetComponent<CharacterMovementScript>().Direction;
         aimMode = attacker.GetComponent<CharacterMovementScript>().AimMode;
         if (aimMode)
         {
             testIKScript = GameObject.FindGameObjectWithTag("Player").GetComponent<TestIKScript>();
             position = testIKScript.lookObj.position;
             this.transform.LookAt(position);
         }
         else
         {
             //Debug.Log("Tossed Grenade");
             position = GameObject.FindGameObjectWithTag("LookAtObj").transform.position;
             this.transform.LookAt(position);
         }
     }
     else if (attacker.GetComponent<GuardController>())
     {
         if (attacker.GetComponent<GuardController>().movingSpeed < 0)
             direction = true;
         else
             direction = false;
     }
     else
     {
         position = GameObject.FindGameObjectWithTag("Player").transform.position;
         this.transform.LookAt(position);
     }
 }
开发者ID:chane1994,项目名称:OperationHarvest,代码行数:33,代码来源:BulletMovement.cs


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