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


C# GameObject.GetComponent方法代码示例

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


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

示例1: Create

		public static void Create(Vector3 pos, string text, ColorRgba color)
		{
			GameObject pe = new GameObject(GameRes.Data.Prefabs.PowerupEffect_Prefab);
			pe.GetComponent<PowerupEffect>().Text = text;
			pe.GetComponent<TextRenderer>().ColorTint = color;
			pe.Transform.Pos = pos;
			Scene.Current.RegisterObj(pe);
		}
开发者ID:Andrea,项目名称:duality-withsvn-history,代码行数:8,代码来源:PowerupEffect.cs

示例2: DropDownListButton

 public DropDownListButton(GameObject btnObj)
 {
     gameobject = btnObj;
     rectTransform = btnObj.GetComponent<RectTransform>();
     btnImg = btnObj.GetComponent<Image>();
     btn = btnObj.GetComponent<Button>();
     txt = rectTransform.FindChild("Text").GetComponent<Text>();
     img = rectTransform.FindChild("Image").GetComponent<Image>();
 }
开发者ID:GlitchBoss,项目名称:TextWars,代码行数:9,代码来源:DropDownListButton.cs

示例3: OnJoinMatch

 public void OnJoinMatch(GameObject script)
 {
     string server_Name = script.GetComponent<MainMenuButtons_script> ().roomNameJoin;
     string server_Password = script.GetComponent<MainMenuButtons_script> ().roomPasswordJoin;
     foreach (var match in manager.matches) {
         if (match.name == server_Name) {
             manager.matchMaker.JoinMatch (match.networkId, server_Password, manager.OnMatchJoined);
         }
     }
 }
开发者ID:clubeprogramacao,项目名称:Random-Arena,代码行数:10,代码来源:NetworkManagerHUD_Custom.cs

示例4: FindCollisionPoint

        private static CollisionPoint FindCollisionPoint(GameObject gameObject, GameObject other, Vector2 oldPosition, Vector2 newPosition)
        {
            if (gameObject.GetComponent<Collider>() is CircleCollider){

                if (other.GetComponent<Collider>() is CircleCollider)
                {
                    CircleCollider objCollider = (CircleCollider) gameObject.GetComponent<Collider>();
                    CircleCollider otherCollider = (CircleCollider) other.GetComponent<Collider>();

                    float distance = Vector2.Distance(newPosition, other.Position);

                    if (distance < objCollider.Radius + otherCollider.Radius)
                    {
                        return new CollisionPoint(oldPosition);
                    }
                }
                else if (other.GetComponent<Collider>() is SquareCollider)
                {
                    CircleCollider objCollider = (CircleCollider)gameObject.GetComponent<Collider>();
                    SquareCollider otherCollider = (SquareCollider)other.GetComponent<Collider>();

                    float distanceX = other.Position.X - newPosition.X;
                    float distanceY = other.Position.Y - newPosition.Y;

                    bool xCollision = Math.Abs(distanceX) < otherCollider.Width/2 + objCollider.Radius;
                    bool yCollision = Math.Abs(distanceY) < otherCollider.Height / 2 + objCollider.Radius;

                    if (xCollision && yCollision)
                    {
                        float xMove = newPosition.X - oldPosition.X;
                        float yMove = newPosition.Y - oldPosition.Y;
                        if (oldPosition.X + objCollider.Radius < other.Position.X - otherCollider.Width/2 ||
                                oldPosition.X - objCollider.Radius > other.Position.X + otherCollider.Width / 2)
                        {
                            oldPosition.Y += yMove;
                            //newPosition = new Vector2(0f, oldPosition.Y + yMove);

                        }
                        if (oldPosition.Y + objCollider.Radius < other.Position.Y - otherCollider.Height / 2 ||
                                oldPosition.Y - objCollider.Radius > other.Position.Y + otherCollider.Height / 2)
                        {
                            oldPosition.X += xMove;
                            //newPosition.X += oldPosition.X + xMove;
                            //newPosition = new Vector2(oldPosition.X + xMove, 0f);
                        }
                        return new CollisionPoint(oldPosition);
                    }
                }

            }

            return null;
        }
开发者ID:njustesen,项目名称:local-rts,代码行数:53,代码来源:CollisionManager.cs

示例5: CloneGameObject

		[Test] public void CloneGameObject()
		{
			Random rnd = new Random();
			GameObject source = new GameObject("ObjectA");
			source.AddComponent(new TestComponent(rnd));
			GameObject target = source.DeepClone();
			
			Assert.AreNotSame(source, target);
			Assert.AreEqual(source.Name, target.Name);
			Assert.AreEqual(source.GetComponent<TestComponent>(), target.GetComponent<TestComponent>());
			Assert.AreNotSame(source.GetComponent<TestComponent>(), target.GetComponent<TestComponent>());
			Assert.AreNotSame(source.GetComponent<TestComponent>().TestReferenceList, target.GetComponent<TestComponent>().TestReferenceList);
		}
开发者ID:undue,项目名称:duality,代码行数:13,代码来源:SpecificCloningTest.cs

示例6: CheckCollision

        internal static Vector2 CheckCollision(GameObject gameObject, Vector2 position)
        {
            foreach (GameObject other in GameObject.GameObjects)
            {

                if (other == gameObject){
                    continue;
                }

                Projectile projectile = gameObject.GetComponent<Projectile>();
                Projectile projectileOther = other.GetComponent<Projectile>();
                if ((projectile != null && projectile.Owner == other) || (projectileOther != null && projectileOther.Owner == gameObject))
                {
                    continue;
                }

                Collider otherCollider = other.GetComponent<Collider>();

                if (otherCollider == null)
                {
                    continue;
                }

                 // if inside
                CollisionPoint collisionPoint = FindCollisionPoint(gameObject, other, gameObject.Position, position);
                if (collisionPoint != null)
                {
                    position = collisionPoint.Point;
                    gameObject.OnCollision(other, position);
                }
            }

            return position;
        }
开发者ID:njustesen,项目名称:local-rts,代码行数:34,代码来源:CollisionManager.cs

示例7: OnStart

    public void OnStart()
    {
        GameObject panel = GameObject.GetGameObjectByName("PuzzleButton1").transform.GetChild(0).gameObject;
        panel1 = GetScript<BoobyTrapDeactivator>(panel);
        panel = GameObject.GetGameObjectByName("PuzzleButton2").transform.GetChild(0).gameObject;
        panel2 = GetScript<BoobyTrapDeactivator>(panel);
        panel = GameObject.GetGameObjectByName("PuzzleButton3").transform.GetChild(0).gameObject;
        panel3 = GetScript<BoobyTrapDeactivator>(panel);
        panel = GameObject.GetGameObjectByName("PuzzleButton4").transform.GetChild(0).gameObject;
        panel4 = GetScript<BoobyTrapDeactivator>(panel);

        trapLightW = GameObject.GetGameObjectByName("TrapLightW");
        trapLightR1 = GameObject.GetGameObjectByName("TrapLightR1");
        trapLightR1script = GetScript<PulsingLightScript>(trapLightR1);
        trapLightR2 = GameObject.GetGameObjectByName("TrapLightR2");
        trapLightR2script = GetScript<PulsingLightScript>(trapLightR2);
        trapLightR3 = GameObject.GetGameObjectByName("TrapLightR3");
        trapLightR3script = GetScript<PulsingLightScript>(trapLightR3);
        trapLightR4 = GameObject.GetGameObjectByName("TrapLightR4");
        trapLightR4script = GetScript<PulsingLightScript>(trapLightR4);

        poisonGas = GameObject.GetGameObjectByName("TSR_PoisonGas");
        gas = poisonGas.GetComponent<CParticleEmitter>();
        gasScript = GetScript<TransformRiserScript>(poisonGas);

        GameObject boobyControllerObj = GameObject.GetGameObjectByName("TSR_TrapController");//trapControllerName);
        controllerScript = GetScript<BoobyTrapDeactivatorController>(boobyControllerObj);

        gasTimerShutdown = gas.mEmitterProperty.mMaxLifetime;

        mSound = gameObject.RequireComponent<CSound>();
    }
开发者ID:Reticulatas,项目名称:MochaEngineFinal,代码行数:32,代码来源:BoobyTrapControllerScript.cs

示例8: Create

 public static void Create(Vector3 pos, float intensity)
 {
     GameObject explo = new GameObject(GameRes.Data.Prefabs.ExploEffect_Prefab);
     explo.GetComponent<ExploEffect>().Intensity = intensity;
     explo.Transform.Pos = pos;
     Scene.Current.RegisterObj(explo);
 }
开发者ID:Andrea,项目名称:dualityTechDemos,代码行数:7,代码来源:ExploEffect.cs

示例9: UpdatePosition

		private void UpdatePosition(GameObject obj, float speed)
		{
			Vector3 pos = obj.Transform.Pos;
			float textureWidth = obj.GetComponent<SpriteRenderer>().SharedMaterial.Res.MainTexture.Res.Size.X;

			pos.X -= speed;
			if (pos.X < -textureWidth) pos.X += textureWidth;

			obj.Transform.Pos = pos;
		}
开发者ID:ChrisLakeZA,项目名称:duality,代码行数:10,代码来源:BackgroundScroller.cs

示例10: TestGameObject

 public new bool TestGameObject(GameObject go)
 {
     var result = false;
     var c = go.GetComponent(Type, true);
     if (c != null)
     {
         result = base.TestGameObject(go);
     }
     return result;
 }
开发者ID:tempdban,项目名称:UCR-1,代码行数:10,代码来源:ComponentFilter.cs

示例11: OnCollision

        public override void OnCollision(GameObject other, Vector2 position)
        {
            var health = other.GetComponent<Health>();
            AttachedTo.MarkForDestruction();
            if (health == null)
                return;
            health.CurrentHealth -= Damage;
            Console.WriteLine(health.CurrentHealth);

            //other.MarkForDestruction();
        }
开发者ID:njustesen,项目名称:local-rts,代码行数:11,代码来源:Projectile.cs

示例12: BehaviourTreeNode

 public BehaviourTreeNode(
     Game1 game,
     GameObject parent, 
     BehaviourNodeType type)
 {
     this._type = type;
     this._state = BehaviourNodeState.Ready;
     this._children = new List<BehaviourTreeNode>();
     this._behaviourComponent = (BehaviourComponent)parent.GetComponent(ComponentType.Behaviour);
     this._parent = parent;
     this._game = game;
 }
开发者ID:patpaquette,项目名称:SSB-clone,代码行数:12,代码来源:BehaviourTreeNode.cs

示例13: OnTriggerEnter

 void OnTriggerEnter(GameObject collider)
 {
     var bc = collider.GetComponent<BulletControl>();
     if (bc != null)
     {
         if (bc.Side == Side.Player)
         {
             Destroy(Owner);
             Destroy(collider);
         }
     }
 }
开发者ID:remy22,项目名称:BlueberryEngine,代码行数:12,代码来源:EnemyControl.cs

示例14: Matches

        /// <summary>
        /// Returns true if the specified <see cref="GameObject"/> has any of the matching
        /// <see cref="Component"/> types, or if the filter is empty.
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public bool Matches(GameObject obj)
        {
            if (this.typeIds.Count == 0) return true;

            this.UpdateTypeCache();
            foreach (Type type in this.typeCache)
            {
                if (obj.GetComponent(type) != null)
                    return true;
            }

            return false;
        }
开发者ID:SirePi,项目名称:duality,代码行数:19,代码来源:GameObjectTypeFilter.cs

示例15: GetBestPath

        public bool GetBestPath(GameObject obj, GameTime gameTime, AStarGraph graph)
        {
            Stack<AStarNode> path = new Stack<AStarNode>();

            Transform2DComponent transformComponent =
                (Transform2DComponent)obj.GetComponent(ComponentType.Transform2D);
            AStarComponent aStarComponent =
                (AStarComponent)obj.GetComponent(ComponentType.AStar);

            if (transformComponent == null || aStarComponent == null)
            {
                return false;
            }

            AStarNode entityNode = graph.GetClosestNode(transformComponent.GetTranslation());
            aStarComponent.CurrentNode = entityNode;
            AStarNode goalNode;

            if (aStarComponent.Follow)
            {
                GameObject entity = aStarComponent.EntityToFollow;
                Transform2DComponent entityTransformComponent =
                    (Transform2DComponent)entity.GetComponent(ComponentType.Transform2D);
                aStarComponent.EntityToFollowPosBuffer = entityTransformComponent.GetTranslation();

                goalNode = graph.GetClosestNode(aStarComponent.EntityToFollowPosBuffer);
            }
            else
            {
                goalNode = graph.GetClosestNode(aStarComponent.GoalPosition);
            }

            this.resolvePath(aStarComponent, entityNode, goalNode, graph);

            return true;
        }
开发者ID:patpaquette,项目名称:SSB-clone,代码行数:36,代码来源:AStarPathfindingSystem.cs


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