本文整理汇总了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);
}
示例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;
}
}
示例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;
}
}
示例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;
}
示例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;
}
}
示例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;
}
}
示例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 ();
}
示例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 ();
}
}
}
示例9: OnParticleCollision
void OnParticleCollision(GameObject other)
{
//Die ();
BulletTester bullets = other.GetComponentInParent<BulletTester>();
if(bullets == null) return;
bullets.HitEnemy();
}
示例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>();
}
}
示例11: CmdDealDamage
protected virtual void CmdDealDamage(GameObject go)
{
var mortalScript = go.GetComponentInParent<MortalObjectScript>();
if (mortalScript != null)
mortalScript.ReceiveDamage (damage);
}
示例12: TriggerTeleport
void TriggerTeleport(GameObject aColliderGo)
{
PlayerStat playerStat = aColliderGo.GetComponentInParent<PlayerStat> ();
if (playerStat != null) {
OnTriggerTeleport(m_MapToTeleport, m_SpawnPointToTeleport);
}
}
示例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());
}
示例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;
}
}
}
示例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();
}
}
}