- Home /
How to call a child by tag or name
Hi guys im having trouble to call an object calles "Stone3", that is a child from the firs person controller. I have tried with name and with tag, but it doesnt work beacuse is child. I know that there is an option with transform.findchild, but i really dont know how to include it. Here is the code
#pragma strict
public var playerAnim : PlayerControl;
var animal : GameObject;
var sound1: AudioClip;
var enrango = false;
playerAnim = GameObject.Find("FPSArms_Axe@Idle").GetComponent(PlayerControl);
function Update (){
if (enrango == true && Input.GetButtonDown("Fire1") && playerAnim.canSwing == true){
animal.GetComponent(vidaanimales).animalHealth -= 1;
audio.PlayOneShot(sound1);
}
}
function OnTriggerEnter (other : Collider) {
if(other.gameObject.name == "Stone3"){
enrango = true;
}
}
function OnTriggerExit (other : Collider) {
if(other.gameObject.name == "Stone3"){
enrango = false;
}
}
Comment
Answer by meat5000 · Mar 01, 2015 at 03:25 AM
I dont think this :
playerAnim = GameObject.Find("FPSArms_Axe@Idle").GetComponent(PlayerControl);
will work outside a function. Put it in Start().
Declare a transform
var stone3 : Transform;
Then inside a function use
stone3 = transform.Find("Stone3");
Your answer
![](https://koobas.hobune.stream/wayback/20220613184629im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Find a child with a name, how to?? 5 Answers
JS, get child 2 Answers
GameObjectWithTag Child 1 Answer
Get object child list with tag 2 Answers
Find children by tag from Player 1 Answer