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


C# GameObject.GetComponentInParent方法代码示例

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


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

示例1: Start

	void Start () {
		//get this waypoint's marker
		WaypointMarker = transform.Find ("WaypointMarker").gameObject;

		GameObject p = GameObject.FindWithTag ("Player");
		GameObject mc = GameObject.FindWithTag ("MainCamera");
		if (p) {
			PlayerController = p.GetComponent<CharacterController> () as CharacterController;
		} else {
			Debug.LogError("No GameObject with tag 'Player' exists. Make sure you have a Player GameComponent and it is tagged, 'Player'.");
		}

		if (mc) {
			GazeCam = mc.GetComponent<Camera>() as Camera;
		} else {
			Debug.LogError("No GameObject with tag 'MainCamera' exists. Make sure you have a MainCamera GameComponent and it is tagged, 'MainCamera'.");
		}

		WPNavigator = PlayerController.GetComponent<WayPointNavigator>();

		//set all child DetailPoints invisible
		foreach(Transform child in transform){
			if(child.CompareTag("DetailPoint")){
				DetailPoints.Add(child.gameObject);
				child.gameObject.SetActive(false);
			}
		}

		//set-up click eventfor waypointMarker
		EventTrigger trigger = WaypointMarker.GetComponentInParent<EventTrigger>();
		EventTrigger.Entry entry = new EventTrigger.Entry();
		entry.eventID = EventTriggerType.PointerClick;
		entry.callback.AddListener( (eventData) => { HandleClick(eventData); } );
		trigger.triggers.Add(entry);
	}
开发者ID:cronkite-asu,项目名称:VRoggingTemplate,代码行数:35,代码来源:WayPointController.cs

示例2: GetSprite

 //    void OnTriggerExit2D(Collider2D coll){
 ////		if (coll.transform.position.y > transform.position.y) {
 ////			sr.sortingOrder = originalSorting;
 ////		}
 //    }
 SpriteRenderer GetSprite(GameObject other)
 {
     if (other.GetComponent<SpriteRenderer> () != null) {
         return other.GetComponent<SpriteRenderer> ();
     } else if (other.GetComponentInParent<SpriteRenderer> () != null) { // check the parent
         return other.GetComponentInParent<SpriteRenderer> ();
     } else {
         return null;
     }
 }
开发者ID:cesarrac,项目名称:TheyRise,代码行数:15,代码来源:SortingLayer_Handler.cs

示例3: GetSortingOrder

 int GetSortingOrder(GameObject other)
 {
     if (other.GetComponent<SpriteRenderer> () != null) {
         return other.GetComponent<SpriteRenderer> ().sortingOrder;
     } else if (other.GetComponentInParent<SpriteRenderer> () != null) { // check the parent
         return other.GetComponentInParent<SpriteRenderer> ().sortingOrder;
     } else {
         return 0;
     }
 }
开发者ID:cesarrac,项目名称:TheyRise,代码行数:10,代码来源:SortingLayer_Handler.cs

示例4: GetPerson

	Person GetPerson(GameObject obj) {
		var person = obj.GetComponentInParent<Person> ();
		var proxy = obj.GetComponentInParent<PersonProxy> ();

		if (!person && proxy && proxy.person) {
			person = proxy.person;
		}

		return person;
	}
开发者ID:RichardCzechowski,项目名称:kaizen,代码行数:10,代码来源:pathManager.cs

示例5: OnHitOccurs

	void OnHitOccurs (GameObject attacker, GameObject defender) {
		// TODO: 정리
		var player = attacker.GetComponentInParent <Player> ();
		if (player) {
			dir = new Vector3 (player.Dir.x, player.Dir.y, 0f).normalized;
		}
		var ai = attacker.GetComponentInParent <AI> ();
		if (ai) {
			dir = new Vector3 (ai.Dir.x, ai.Dir.y, 0f).normalized;
		}
	}
开发者ID:breadceo,项目名称:hexelslashheros,代码行数:11,代码来源:ScreenEffect.cs

示例6: DetectedCollider

 private void DetectedCollider(GameObject gameObject)
 {
     var testExplosive = gameObject.GetComponentInParent<ExplosiveObject>();
     //print(test);
     if(testExplosive != null)
     {
         var getGroundMover = gameObject.GetComponentInParent<MovementChecker>();
         _subscribedCollider = testExplosive;
         _groundMover = getGroundMover;
         _groundMover.X_PositionChanged += GroundMoverOnPositionChanged;
     }
 }
开发者ID:symbol24,项目名称:ProjectJuice,代码行数:12,代码来源:ExplosiveObjectDetector.cs

示例7: execute

 public void execute(GameObject player)
 {
     /*
     if (!flag) {
         GetComponent<Transform> ().Translate (-2, 0, 0);
     } else {
         GetComponent<Transform> ().Translate (2, 0, 0);
     }
     flag = !flag;
     */
     player.GetComponentInParent<AudioSource> ().clip = voice;
     player.GetComponentInParent<AudioSource> ().Play ();
 }
开发者ID:UOPshellfire,项目名称:Repository,代码行数:13,代码来源:TombMovement.cs

示例8: InteractDoor

	public void InteractDoor(GameObject currentObject) {		
		if (currentObject.name == "Door") {
			currentObject.GetComponentInParent<Animator>().SetTrigger ("mayOpen");
			if (soundManager.GetComponent<SoundManager> ().myAudioSource [1].isPlaying == false) {
				soundManager.GetComponent<SoundManager> ().OpenDoor ();
				particleSpark.SetActive (true);
			}
		}
		if (currentObject.name == "DoorBroken") {
			currentObject.GetComponentInParent<Animator>().SetTrigger("broken");
			particleSpark.SetActive (true);
			if (soundManager.GetComponent<SoundManager> ().myAudioSource [1].isPlaying == false) {
				soundManager.GetComponent<SoundManager> ().OpenBrokenDoor ();
			}
		}
    }
开发者ID:Fahrettin52,项目名称:Game-Lab-2.1,代码行数:16,代码来源:Interaction.cs

示例9: OnParticleCollision

 void OnParticleCollision(GameObject other)
 {
     //Die ();
     BulletTester bullets = other.GetComponentInParent<BulletTester>();
     if(bullets == null) return;
     bullets.HitEnemy();
 }
开发者ID:LGriggles,项目名称:Trout-Run,代码行数:7,代码来源:CollisionTestWall.cs

示例10: AddGNStringText

    private static void AddGNStringText(MenuCommand menuCommand)
    {
        GameObject go = new GameObject("Text");
        GameObjectUtility.SetParentAndAlign(go, menuCommand.context as GameObject);
        if(go.GetComponentInParent<Canvas>()== null)
        {
            var canvas = Object.FindObjectOfType<Canvas>();
            if(canvas == null)
            {
                var goCanvas = new GameObject("Canvas");
                canvas = goCanvas.AddComponent<Canvas>();
                canvas.renderMode = RenderMode.ScreenSpaceOverlay;
                goCanvas.AddComponent<UnityEngine.UI.CanvasScaler>();
                goCanvas.AddComponent<UnityEngine.UI.GraphicRaycaster>();
            }

            go.transform.SetParent(canvas.transform);
            go.transform.localPosition = Vector3.zero;
        }

        go.AddComponent<GNText>();
        Undo.RegisterCreatedObjectUndo(go, "Create " + go.name);
        Selection.activeObject = go;

        if(GNStringManager.instance == null)
        {
            var sm = new GameObject("StringManager");
            sm.AddComponent<GNStringManager>();
        }

        
    }
开发者ID:geniikw,项目名称:GNStringPackage,代码行数:32,代码来源:GNStringStaticClass.cs

示例11: CmdDealDamage

    protected virtual void CmdDealDamage(GameObject go)
    {
        var mortalScript = go.GetComponentInParent<MortalObjectScript>();

        if (mortalScript != null)
            mortalScript.ReceiveDamage (damage);
    }
开发者ID:hrajagop,项目名称:2DShooter,代码行数:7,代码来源:BulletScript.cs

示例12: TriggerTeleport

 void TriggerTeleport(GameObject aColliderGo)
 {
     PlayerStat playerStat = aColliderGo.GetComponentInParent<PlayerStat> ();
     if (playerStat != null) {
         OnTriggerTeleport(m_MapToTeleport, m_SpawnPointToTeleport);
     }
 }
开发者ID:TheLastShade,项目名称:cathar,代码行数:7,代码来源:MapTeleport.cs

示例13: CmdHallucinateSpawn

    public void CmdHallucinateSpawn(GameObject target, float radius, int numMinions, Action<GameObject[], GameObject> completion)
    {
        List<Node> nodes = GridBehavior.Instance.getNodesNearPos(target.transform.position, radius, node => !node.hasLight && node.canWalk) as List<Node>;
        nodes.Sort((a, b) => UnityEngine.Random.Range(-1, 2));

        Vector3[] positions = new Vector3[numMinions];
        for (int n = 0; n < numMinions; n++)
        {
            positions[n] = nodes[n].position;
        }

        GameObject[] minions = new GameObject[numMinions];
        for (int n = 0; n < numMinions; n++)
        {
            var avatar = target.GetComponentInParent<AvatarController>();

            Transform spawn = minionContainer;
            minions[n] = Instantiate(EnemyPrefab[0], positions[n], Quaternion.identity) as GameObject;
            minions[n].transform.SetParent(spawn);
            minions[n].GetComponent<MinionController>().enabled = true;
            minions[n].GetComponent<MinionController>().SetVisibility(avatar.gameObject);
            NetworkServer.Spawn(minions[n]);

            TextureRandomizer rnd = minions[n].GetComponent<TextureRandomizer>();
            rnd.RandomizeTexture();
        }

        completion(minions, target);

        StartCoroutine(SetGridDirty());
    }
开发者ID:igm-capstone,项目名称:capstone-game-unity,代码行数:31,代码来源:MinionSpawnManager.cs

示例14: ClickShape

    /// <summary>
    /// This method conducts a swap
    /// </summary>
    /// <param name="s"></param>
    void ClickShape(GameObject s)
    {
        if (firstShape == null)
            firstShape = s;
        else
        {
            secondShape = s;
            GameObject p1 = firstShape.transform.parent.gameObject;
            GameObject p2 = secondShape.transform.parent.gameObject;
            c1 = firstShape.GetComponentInParent<Cell>();
            c2 = secondShape.GetComponentInParent<Cell>();
            if (c1.cellID - c2.cellID == 4 ||
                c2.cellID - c1.cellID == 4 ||
                c1.cellID - c2.cellID == 1 ||
                c2.cellID - c1.cellID == 1)
            {
                firstShape.GetComponent<RectTransform>().SetParent(p2.transform);
                secondShape.GetComponent<RectTransform>().SetParent(p1.transform);
                c1.inPlace = false;
                c1.currentShape = secondShape;
                c2.inPlace = false;
                c2.currentShape = firstShape;
                checkMatch = true;
                firstShape = null;
                secondShape = null;
            }

        }
    }
开发者ID:coderDarren,项目名称:MobileMiniGame,代码行数:33,代码来源:ShapeManager.cs

示例15: OnBeginDrag

    public void OnBeginDrag(PointerEventData eventData)
    {
        itemBeingDraggedType = gameObject.GetComponent<ItemType>().itemType;
        itemBeingDragged = gameObject;

        Socket socket = itemBeingDragged.GetComponentInParent<Socket>();

        Item i = itemBeingDragged.GetComponent<Item>();
        if ( i != null ){
            i.turnOffPower();
            i.equipped = false;
        }

        startPosition = gameObject.transform.position;
        startParent = gameObject.transform.parent;
        gameObject.GetComponent<CanvasGroup>().blocksRaycasts = false;
        gameObject.transform.SetParent(_Hover.transform);

        // on picking up the item, trigger a circuit change
        if ( socket != null && socket.parentCircuit != null ){
            //Debug.Log (DateTime.Now.ToString("ssffff") + " IBeginDragHandler");
            if ( itemBeingDragged.GetComponent<ItemType>().itemType != ItemTypes.PowerUnit ){
                socket.parentCircuit.circuitChange();
            }
        }
    }
开发者ID:josephjaniga,项目名称:Billipede,代码行数:26,代码来源:DragHandler.cs


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