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


C# Transform.GetComponent方法代码示例

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


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

示例1: SetColor

 void SetColor(Transform _transform, Color _color)
 {
     mText = _transform.GetComponent<Text> ();
     if (mText != null){
         mText.color = _color;
     }
     mLight = _transform.light;
     if (mLight != null){
         mLight.color = _color;
     }
     mImage = _transform.GetComponent<Image> ();
     if (mImage != null) {
         mImage.color = _color;
     }
     mSpriteRender = _transform.GetComponent<SpriteRenderer> ();
     if (mSpriteRender != null) {
         mSpriteRender.color = _color;
     }
     if (_transform.renderer != null) {
         mMat = _transform.renderer.material;
         if (mMat != null) {
             mMat.color = _color;
         }
     }
     if (includeChilds) {
         for (int i = 0; i < _transform.childCount; ++i) {
             Transform child = _transform.GetChild(i);
             SetColor(child, _color);
         }
     }
 }
开发者ID:felixfei,项目名称:ugui-Tween-Tool,代码行数:31,代码来源:uTweenColor.cs

示例2: Update

        private void Update()
        {
            if (GetComponent<ActionsOnlyInCanvas>() == null ||
                GetComponent<ActionsOnlyInCanvas>().IsMousePosInsideCanvas)
            {
                var ray = PlayerCamera.ScreenPointToRay(Input.mousePosition);
                RaycastHit hit;

                if (Physics.Raycast(ray, out hit, 100))
                {
                    CurrentHex = hit.transform;

                    if (Input.GetMouseButton(0))
                        if (HexSelected != null) HexSelected(this, new HexCoordEventArgs(CurrentHex.GetComponent<HexData>().HexPosition));

                    if (HexHitted != null) HexHitted(this, new HexCoordEventArgs(CurrentHex.GetComponent<HexData>().HexPosition));

                }
                else if (CurrentHex)
                {
                    CurrentHex = null;
                    if (NoHexHitted != null) NoHexHitted(this, EventArgs.Empty);
                }
                else if (Input.GetMouseButton(0))
                {
                    if (NoHexSelected != null) NoHexSelected(this, EventArgs.Empty);
                }
            }
        }
开发者ID:Zunderbird,项目名称:HexGridAlgorithms,代码行数:29,代码来源:MouseActionsCatcher.cs

示例3: colorFrom

        public Tween colorFrom( Transform trans, float duration, Color targetColor, string materialProperty = "_Color", bool isRelativeTween = false )
        {
            var currentColor = trans.GetComponent<Renderer>().material.GetColor( materialProperty );
            trans.GetComponent<Renderer>().material.SetColor( materialProperty, targetColor );

            return colorTo( trans, duration, currentColor, materialProperty, isRelativeTween );
        }
开发者ID:prime31,项目名称:GoKitLite,代码行数:7,代码来源:GoKitLite.cs

示例4: Start

		void Start ()
		{
			player = GameObject.FindWithTag ("Player").transform;
			pHealth = player.GetComponent<PlayerHealth> ();
			pAttack = player.GetComponent<PlayerAttack> ();
			eHealth = GetComponent<EnemyHealth> ();
			Rigidbody = GetComponent<Rigidbody> ();
		}
开发者ID:IntroPixelGames,项目名称:tankbattle,代码行数:8,代码来源:EnemyMovement.cs

示例5: Awake

		void Awake ()
		{
			PTank = GameObject.Find("PlayerTank(Clone)").transform;
			ETank = GameObject.Find("EnemyTank_Hard(Clone)").transform;
			pHealth = PTank.GetComponent<PlayerHealth> ();
			eHealth = ETank.GetComponent<EnemyHealth> ();
			eMove = ETank.GetComponent<EnemyMovement> ();
		}
开发者ID:IntroPixelGames,项目名称:tankbattle,代码行数:8,代码来源:Enemy_HardAttack.cs

示例6: Activate

 public override void Activate(BTDatabase database)
 {
     base.Activate(database);
     _trans = database.transform;
     seeker = _trans.GetComponent<Seeker>();
     controller = _trans.GetComponent<CharacterController>();
     seeker.pathCallback += OnPathComplete;
 }
开发者ID:zs9024,项目名称:Jungle,代码行数:8,代码来源:BTActionPathFind.cs

示例7: BuffCalculation

 public BuffCalculation(Transform character)
 {
     Character = character;
     property = character.GetComponent<CharacterProperty>();
     buffList = character.GetComponent<BuffList>();
     selection = character.GetComponent<CharacterSelect>();
     addBuff = (BuffType[])buffList.addBuff.Clone();
     deBuff = (BuffType[])buffList.deBuff.Clone();
     playerSide = property.Player;
 }
开发者ID:hugobozzshih007,项目名称:BattleCard,代码行数:10,代码来源:BuffCalculation.cs

示例8: Fire

        /// <summary>
        /// Fire a specified projectile.
        /// </summary>
        /// <param name="projectile">Projectile.</param>
        /// <param name="lookAt">Look at direction.</param>
        protected void Fire(Transform projectile, Vector3 lookAt)
        {
            projectile.position = this.transform.TransformPoint(this.spawnPosition);
            var component = projectile.GetComponent<Projectile>();
            component.targetTag = this.targetTag;
            component.targetPosition = lookAt;

            var particles = projectile.GetComponent<ParticleSystem>();
            particles.Clear(true);
            particles.Play(true);
        }
开发者ID:intentor,项目名称:sensewizard,代码行数:16,代码来源:ProjectileLauncher.cs

示例9: FindAnimatorRecursive

		// Finds the first Animator/Animation up the hierarchy
		private void FindAnimatorRecursive(Transform t, bool findInChildren) {
			if (isAnimated) return;

			animator = t.GetComponent<Animator>();
			animation = t.GetComponent<Animation>();

			if (isAnimated) return;

			if (animator == null && findInChildren) animator = t.GetComponentInChildren<Animator>();
			if (animation == null && findInChildren) animation = t.GetComponentInChildren<Animation>();

			if (!isAnimated && t.parent != null) FindAnimatorRecursive(t.parent, false);
		}
开发者ID:ChemaLeon,项目名称:RitualCops,代码行数:14,代码来源:SolverManager.cs

示例10: PlayAnimation

		public static bool PlayAnimation (Transform sprite, string clipName, bool changeWrapMode, WrapMode wrapMode, int frame)
		{
			#if tk2DIsPresent
			
			tk2dSpriteAnimationClip.WrapMode wrapMode2D = tk2dSpriteAnimationClip.WrapMode.Once;
			if (wrapMode == WrapMode.Loop)
			{
				wrapMode2D = tk2dSpriteAnimationClip.WrapMode.Loop;
			}
			else if (wrapMode == WrapMode.PingPong)
			{
				wrapMode2D = tk2dSpriteAnimationClip.WrapMode.PingPong;
			}
			
			if (sprite && sprite.GetComponent <tk2dSpriteAnimator>())
			{
				tk2dSpriteAnimator anim = sprite.GetComponent <tk2dSpriteAnimator>();
				tk2dSpriteAnimationClip clip = anim.GetClipByName (clipName);

				if (clip != null)
				{
					if (!anim.IsPlaying (clip))
					{
						if (changeWrapMode)
						{
							clip.wrapMode = wrapMode2D;
						}
						
				    	anim.Play (clip);

						if (frame >= 0)
						{
							anim.ClipFps = 1f;
							anim.SetFrame (frame);
						}
					}
					
					return true;
				}

				return false;	
			}
			
			#else
			Debug.Log ("The 'tk2DIsPresent' preprocessor is not defined - check your Build Settings.");
			#endif
			
			return true;
		}
开发者ID:amutnick,项目名称:CrackTheCode_Repo,代码行数:49,代码来源:tk2DIntegration.cs

示例11: Act

		public override void Act(Transform player, Transform npc)
		{
			//攻撃フラグを初期化
			npc.GetComponent<EnemyCtrl> ().StateStartCommon ();

			//ターゲット地点をプレーヤーポジションに設定
			this.SetDest (player);

			//ターゲット地点に回転
			if(IsTestScene())
			this.SetRot (npc, npc.position);

			//目的地をプレイヤーに変更
			npc.GetComponent<CharaMove> ().SendMessage ("SetDestination", destPos);
		}
开发者ID:trananh1992,项目名称:3DActionGame,代码行数:15,代码来源:ApproachState.cs

示例12: SetupGeometryAndAppearance

 public override void SetupGeometryAndAppearance()
 {
     Tip = part.FindModelTransform("Tip");
     Root = part.FindModelTransform("Root");
     SMRcontainer = part.FindModelTransform("Collider");
     wingSMR = SMRcontainer.GetComponent<SkinnedMeshRenderer>();
 }
开发者ID:RichardDastardly,项目名称:pWingsMerged,代码行数:7,代码来源:ManipulatorWing.cs

示例13: Reason

		public override void Reason(Transform player, Transform npc)
		{
			this.SetDest (player);
			this.SetDist (Vector3.Distance (npc.position, destPos));
		
			if(this.LessThanCheckReach(dist, 2.0f))
			{
				Debug.Log("Switch to Attack state");
				npc.GetComponent<EnemyCtrl>().SetTransition(Transition.ReachPlayer);
			}
			else if(this.GreaterThanCheckReach(dist, 10.0f))
			{
				Debug.Log("Switch to Search state");
				npc.GetComponent<EnemyCtrl>().SetTransition(Transition.LostPlayer);
			}
		}
开发者ID:trananh1992,项目名称:3DActionGame,代码行数:16,代码来源:ApproachState.cs

示例14: Create

 public static PathFollower Create(Transform transform)
 {
     var pathFollower = transform.GetComponent<PathFollower>();
     if (pathFollower == null) pathFollower = transform.gameObject.AddComponent<PathFollower>();
     pathFollower._transform = transform;
     return pathFollower;
 }
开发者ID:davidMa88,项目名称:shotemup_repo,代码行数:7,代码来源:PathFollower.cs

示例15: RemoveRagdollComponents

        /// <summary>
        /// Removes all the ragdoll components (except Cloth colliders), including compound colliders that are not used by Cloth. Components on the 'target' GameObject will not be touched for they are probably not ragdoll components, but required by a character controller.
        /// </summary>
        /// <param name="target">Target.</param>
        public static void RemoveRagdollComponents(Transform target, int characterControllerLayer)
        {
            if (target == null) return;

            // Get rid of all the ragdoll components on the target
            Rigidbody[] rigidbodies = target.GetComponentsInChildren<Rigidbody>();
            Cloth[] cloths = target.GetComponentsInChildren<Cloth>();

            for (int i = 0; i < rigidbodies.Length; i++) {
                if (rigidbodies[i].gameObject != target.gameObject) {
                    var joint = rigidbodies[i].GetComponent<Joint>();
                    var collider = rigidbodies[i].GetComponent<Collider>();

                    if (joint != null) DestroyImmediate(joint);
                    if (collider != null) {
                        if (!IsClothCollider(collider, cloths)) DestroyImmediate(collider);
                        else collider.gameObject.layer = characterControllerLayer;
                    }
                    DestroyImmediate(rigidbodies[i]);
                }
            }

            // Get rid of (compound) colliders that are not used by Cloth
            Collider[] colliders = target.GetComponentsInChildren<Collider>();

            for (int i = 0; i < colliders.Length; i++) {
                if (colliders[i].transform != target && !IsClothCollider(colliders[i], cloths)) {
                    DestroyImmediate(colliders[i]);
                }
            }

            // Get rid of the PuppetMaster
            var puppetMaster = target.GetComponent<PuppetMaster>();
            if (puppetMaster != null) DestroyImmediate(puppetMaster);
        }
开发者ID:cupsster,项目名称:ExtremeBusiness,代码行数:39,代码来源:PuppetMasterSetup.cs


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