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


C# Transform.GetComponentInChildren方法代码示例

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


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

示例1: MoveCamera

    public void MoveCamera(Transform cameraTransform, Transform targetTransform)
    {
        // TODO: Maybe let's use DoTween and have it be reasonably smooth instead of falling on our old iTween business
        var positionDifference = targetTransform.position - cameraTransform.position;
        float xSpeed = Mathf.Abs(positionDifference.x) * cameraSnapX;
        //float ySpeed = Mathf.Abs(positionDifference.y) * cameraSnapY;
        float zSpeed = Mathf.Abs(positionDifference.z) * cameraSnapZ;

        //Cap the camera's speed so it doesn't go fucking nuts and start overshooting the player
        if (xSpeed > 60) { xSpeed = 60; }
        if (zSpeed > 60) { zSpeed = 60; }

        if (Mathf.Abs(positionDifference.x) >= cameraFreeX)
        {
            cameraTransform.position = cameraTransform.position.SetX(iTween.FloatUpdate(cameraTransform.position.x, targetTransform.position.x, xSpeed));
        }
        if (Mathf.Abs(positionDifference.z) >= cameraFreeZ)
        {
            cameraTransform.position = cameraTransform.position.SetZ(iTween.FloatUpdate(cameraTransform.position.z, targetTransform.position.z, zSpeed));
        }

        //TODO: Generalize in some way
        if (targetTransform.GetComponentInChildren<GroundCheck>() != null 
            && targetTransform.GetComponentInChildren<GroundCheck>().IsOnGround
            && !State.Instance.IsIntro)
        {
            cameraTransform.position = cameraTransform.position.SetY(iTween.FloatUpdate(cameraTransform.position.y, targetTransform.position.y, 5f));
        }
    }
开发者ID:harjup,项目名称:ChillTreasureTime,代码行数:29,代码来源:CameraMove.cs

示例2: Spawn

 //Spawn new enemy from prefab
 public void Spawn()
 {
     spawnedEnemy = (Transform) Instantiate(enemy, transform.position, transform.rotation);
     spawnedEnemy.GetComponentInChildren<EnemyAttack> ().spawnPoint = transform;
     spawnedEnemy.GetComponentInChildren<Enemy> ().spawnPoint = transform;
     spawnedEnemy.parent = transform;
     needsSpawn = false;
 }
开发者ID:BritishCookieGirl,项目名称:BattleBoy,代码行数:9,代码来源:EnemySpawner.cs

示例3: Activate

    //typeOverride = use to discard what reticle entity is set to,
    // or if there's no entity
    public Reticle Activate(Transform attachTo, Reticle.Type typeOverride=Reticle.Type.NumType)
    {
        Reticle ret = null;
        EntityBase ent = attachTo.GetComponentInChildren<EntityBase>();

        //verify reticle type
        Reticle.Type reticleType = typeOverride;
        if(ent != null && reticleType == Reticle.Type.NumType) {
            reticleType = ent.reticle;
        }

        if(reticleType != Reticle.Type.NumType) {
            ret = attachTo.GetComponentInChildren<Reticle>();

            //add a reticle to target
            if(ret == null) {
                Transform trans = transform;
                Transform child = null;

                //get or create a reticle
                if(trans.childCount > 0) {
                    child = trans.GetChild(0);
                    child.gameObject.SetActiveRecursively(true);
                }
                else {
                    child = Transform.Instantiate(template) as Transform;
                }

                //add child to attachee, then switch its layer to target for grabbing
                child.parent = attachTo;
                Transform childTrans = child.transform;
                Vector2 parentPos = child.parent.position;
                childTrans.position = new Vector3(parentPos.x, parentPos.y, childZOfs);
                childTrans.localRotation = Quaternion.identity;
                childTrans.localScale = Vector3.one;

                ret = childTrans.GetComponentInChildren<Reticle>();

                mActiveReticles.Add(new ReticleHolder(ent, ret));
            }

            //set data
            if(ent != null && !ent.FlagsCheck(Entity.Flag.Targetted)) {
                ent.FlagsAdd(Entity.Flag.Targetted);
                ent.OnTargetted(true);
            }

            ret.Activate(reticleType, ent);
        }

        return ret;
    }
开发者ID:ddionisio,项目名称:GitGirl,代码行数:54,代码来源:ReticleManager.cs

示例4: Awake

    void Awake()
    {
        rb = GetComponentInChildren<Rigidbody>();

        foreach(Transform t in GetComponentsInChildren<Transform>()) {
            if (t.CompareTag("Fist")) {
                fist = t;
                fistMesh = fist.GetComponentInChildren<Collider>();
                break;
            }
        }
        Assert.IsTrue(fist != null, "oh no. we didn't find our fist transform!");
        fist.gameObject.SetActive(false);

        if (isPlayerOne) {
            horizontal = "Horizontal";
            jumpKey = KeyCode.W;
            punchKey = KeyCode.E;
            otherGuysControls = GameObject.Find("PlayerTwo").GetComponent<PlayerControls>();
        } else {
            horizontal = "Horizontal2";
            jumpKey = KeyCode.I;
            punchKey = KeyCode.O;
            otherGuysControls = GameObject.Find("PlayerOne").GetComponent<PlayerControls>();
        }
        Assert.IsTrue(otherGuysControls != null, "what???! didn't find the other guy");

        foreach(Collider c in GetComponentsInChildren<Collider>()) {
            if (c.CompareTag("Body")) {
                _body = c;
                break;
            }
        }
        Assert.IsTrue(_body != null, "huh?? didn't find body collider.");
    }
开发者ID:melsov,项目名称:SmashyBrosGame,代码行数:35,代码来源:PlayerControls.cs

示例5: Awake

    // Use this for initialization
    void Awake()
    {
        myTransform = transform;
        myRigidbody = rigidbody;
        myRigidbody.freezeRotation = true;

        startSpeed = moveSpeed;
        startNextFoot = nextFoot;

        runningSpeed = startSpeed + 2.0f;
        runningNextFoot = nextFoot - 0.25f;

        myState = NPC.Chasing;

        GameObject targetObject = GameObject.Find( "Player" );

        if ( targetObject )
        {
            target = targetObject.transform;

            lanternScript = target.GetComponentInChildren< Lantern >();
        }
        else
        {
            Debug.Log( "no object named player was found" );
        }
    }
开发者ID:johste93,项目名称:UnityProjects,代码行数:28,代码来源:ShadowNPC.cs

示例6: AnimateFade

    private bool AnimateFade(Transform letter, float deltaTime, Vector3 targetPosition)
    {
        if (!letter) {
            return false;
        }

        letter.position = Vector3.Lerp (letter.position,
                                        targetPosition,
                                        _speed * deltaTime);

        float distance = (letter.position - _initPosition).magnitude;

        Image bg = letter.GetComponent<Image>();
        Text fg = letter.GetComponentInChildren<Text>();

        float alpha = 1 - distance / _maxDragDistance;
        alpha = alpha > 0 ? alpha : 0;
        bg.color = new Color(bg.color.r, bg.color.g, bg.color.b, alpha);
        fg.color = new Color(fg.color.r, fg.color.g, fg.color.b, alpha);

        if ((letter.position - targetPosition).magnitude < 0.1 || alpha == 0) {
            letter.position = targetPosition;

            return true;
        }

        return false;
    }
开发者ID:samuraijourney,项目名称:FourUnity,代码行数:28,代码来源:EntryBoxController.cs

示例7: Awake

 void Awake()
 {
     m_transform = transform;
     var ssList = m_transform.GetComponentsInChildren<UISprite>(true);
     if (m_bgUp == null)
     {
         m_bgUp = ssList[0].gameObject;
     }
     if (m_bgUp != null)
     {
         m_bgUpSpriteName = m_bgUp.transform.GetComponentsInChildren<UISprite>(true)[0].spriteName;
     }
     if (m_bgDown == null)
     {
         m_bgDown = ssList[1].gameObject;
     }
     m_lblText = m_transform.GetComponentInChildren<UILabel>();
     if (IsSmart)
     {
         m_transform.localScale = new Vector3(1.0f, 1.0f, 1.0f);
         BoxCollider bc = m_transform.GetComponent<BoxCollider>();
         bc.center = Vector3.zero;
         m_bgUp.transform.localScale = new Vector3(bc.size.x, bc.size.y, 1.0f);
         m_bgDown.transform.localScale = new Vector3(bc.size.x, bc.size.y, 1.0f);
     }
 }
开发者ID:lbddk,项目名称:ahzs-client,代码行数:26,代码来源:MogoTwoStatusButton.cs

示例8: ChangePlayerUser

    //user
    public void ChangePlayerUser(Transform newSelectedPlayer)
    {
        if (newSelectedPlayer == selectedPlayer)
        {
            return;
        }
        Select();
        Transform[] select = tiles.Where(a => Vector3.Distance(newSelectedPlayer.parent.position, a.transform.position) < 3f).ToArray();
        for (int i = 0; i < select.Length; i++)
        {
            select[i].GetComponent<Renderer>().material = matSelect;
        }
        newSelectedPlayer.parent.GetComponent<Renderer>().material = wallMath;
        prevTileSelect = select;
        newSelectedPlayer.GetComponentInChildren<Animator>().Play("Select");
        selectedPlayer = newSelectedPlayer;

        Transform[] clicableTiles = select.Where(a => a.childCount == 0).ToArray();
        if (clicableTiles != null)
        {
            for (int i = 0; i < clicableTiles.Length; i++)
            {
                clicableTiles[i].SendMessage("ChangeClicable");
            }
        }
        prevClickTiles = clicableTiles;
    }
开发者ID:maxCdev,项目名称:GardenBattle,代码行数:28,代码来源:GameController.cs

示例9: Start

	private bool buttonDown = false;	// If player holds the mouse button down.	
	
	void Start()
	{		
		layerMask=~layerMask; // Get all the layers to raycast on, this will allow the raycast to ignore chosen layers.
		myCamera = Camera.main; // Get main camera as the camera will not always be a child GameObject.
		if(myCamera == null)
		{
			Debug.LogError("No main camera, please add camera or set camera to MainCamera in the tag option.");
		}
		myTransform = transform;				

		// Get the NavMeshAgent and set 
		navMeshAgent = myTransform.GetComponent<NavMeshAgent>();			
		navMeshAgent.speed = moveSpeed;
		navMeshAgent.angularSpeed = rotationSpeed;
		navMeshAgent.acceleration = acceleration;
		// Get the player animator in child.
		try
		{
			animator = myTransform.GetComponentInChildren<Animator>();						
		}
		catch(Exception e)
		{
			Debug.LogWarning("No animator attached to character." + e.Message);
		}						
	}
开发者ID:Gapti,项目名称:Starboard_INT,代码行数:27,代码来源:ARPGPlayerNavMove.cs

示例10: Awake

    // Use this for initialization
    void Awake()
    {
        if (StaticRef == null) // if theres is not allerdaye a static ref makes this the static ref
        {
            DontDestroyOnLoad(gameObject);
            StaticRef = this;
        }
        else if (StaticRef != this) // is the allready is a ref , destory this
        {
            Destroy(this);
        }

        player = GameController_script.playerRef;

        sphereRadius = this.GetComponent<SphereCollider>();

        hat = GameObject.FindGameObjectWithTag("hat").transform;

        book = GameObject.FindGameObjectWithTag("book").transform;

        book_anim = book.GetComponentInChildren<Animator>();

        hat.gameObject.SetActive(true);

        book.gameObject.SetActive(false);

        haveHat = HatState.Yes;

        hatSpwanTarget = GameObject.FindGameObjectWithTag("hatSpawn").transform;
    }
开发者ID:Dstaal,项目名称:MasterProject,代码行数:31,代码来源:eventChecker.cs

示例11: Initialize

 public void Initialize(Transform root, Vector3 localPosition)
 {
     visuals = Instantiate(root.GetComponentInChildren<AbstractPlayerVisuals>().gameObject).GetComponent<AbstractPlayerVisuals>();
     visuals.transform.SetParent(this.transform, false);
     visuals.transform.localPosition = Vector3.zero;
     this.transform.SetParent(root, false);
     this.transform.localPosition = localPosition;
 }
开发者ID:Reddeyfish,项目名称:Witches-vs-Aliens-2015-2016,代码行数:8,代码来源:Mirror11.cs

示例12:

    void I_ActorState.OnEnter(Transform actor)
    {
        actor.GetComponent<Animator>().SetBool("IsHit", true);
        actor.GetComponentInChildren<ParticleSystem>().Play();
        actor.GetComponents<AudioSource>()[0].Play();

        actor.GetComponent<ActorStats>().Hurt(damage);
    }
开发者ID:Ethanmn,项目名称:TurkeyJam2015,代码行数:8,代码来源:Santa_HitState.cs

示例13: Awake

 // Use this for initialization
 void Awake()
 {
     model = transform.Find("Model");
     if (FindObjectOfType<SpacePlayer>())
     {
         var tex = FindObjectOfType<SpacePlayer>().GetComponentInChildren<Renderer>().material.mainTexture;
         model.GetComponentInChildren<Renderer>().material.mainTexture = tex;
     }
 }
开发者ID:vildninja,项目名称:ngj14,代码行数:10,代码来源:VictoryAnimation.cs

示例14: Act

 public override void Act(Transform player)
 {
     //status update
     Debug.Log ("Enemy is about to explode");
     //AudioSource.PlayClipAtPoint (sound, this.transform.position);
     Destroy(Instantiate(this.effect, this.transform.position, this.transform.rotation),7.0f);
     player.GetComponentInChildren<PlayerInfo> ().GainEnergy (energyRestore);
     lootTable.GetComponent<LootTable> ().dropLoot (this.transform);
     Destroy (gameObject);
 }
开发者ID:jberg03,项目名称:GSP494-Team-A,代码行数:10,代码来源:DeadState.cs

示例15: Start

 // Use this for initialization
 void Start()
 {
     thruster = transform.FindChild("Thruster");
     thruster.GetComponentInChildren<Light>().intensity = 0;
     SpriteRenderer sp = this.GetComponent<SpriteRenderer>();
     if (damageoremp) { //color of main sprite
         sp.color = damagecolor;
     } else {
         sp.color = empcolor;
     }
 }
开发者ID:ajm1996,项目名称:SpaceSalvage,代码行数:12,代码来源:MissileScript.cs


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