- Home /
Finding child problems..
I have this script and it doesn't make the old RangedItem get dequipped from Player and doesn't get activated so i'm amusing its not being found, help??
private var Player : Transform;
var Item : GameObject;
function OnTriggerStay2D(other: Collider2D){
if(other.transform.gameObject.name == "Player"){
if(Input.GetKey(KeyCode.E)){
var Item = GameObject.Find("/RangeItem");
if(Item){
Item.SetActive(true);
Item.transform.parent = null;
}
}
}
}
function Start(){
Player = GameObject.FindWithTag("Player").transform;
}
Try ins$$anonymous$$d of name gameObject.tag == "Player" and also when finding the item use GameObject.FindGameObjectWithTag("blabla").
To see if it is working try taking out the if(Input) and see how the parent = null
I'd also include some Debug.Log("blabla1") to each if condition :) And your item's name is '/RangedItem' or just 'RangeItem'?
its just RangedItem but I saw something that / would search for a child which is what im looking for not that its parentless
Your answer
Follow this Question
Related Questions
Make a simple tree 1 Answer
Access children using Find() returns 'null'? 3 Answers
how do I get reference to a parent or a child? 2 Answers