Hello i have a game where you need to create your own axe to be able to cut down trees (the basic you know). But i have some problems, first you need a stone and a sitck to be able to craft it. When you have crafted it, it wil spawn infront of you (a prefab). Then i have an axe on my main camera that is going to dislay when i rightclick on the axe on the ground. Here comes the problem, my axe that spawns is a prefab, and my axe in the hand (that is going to display) is a gameobject, and as you know a prefab can not see a gameobject in the scene, so thats why i added a line in my code :
function Update ()
{
StoneAxeInHandObj = GameObject.Find("StoneAxeInHand");
}
So when ever the axe spawns in the scene it will find where the axe in the hand. But when i try my game it still doesn’t work, it still doesn’t fill in the “StoneAxeInHandObj”. What is the reason? I have that line of code in the Update function?
Rest of “pickUpStoneAxe” Script:
#pragma strict
var style : GUIStyle;
var StoneAxeInHandObj : GameObject;
private var showPickUp : boolean = false;
function Update ()
{
StoneAxeInHandObj = GameObject.Find("StoneAxeInHand");
}
function Start ()
{
StoneAxeInHandObj.SetActive(false);
}
function OnTriggerStay (Col : Collider)
{
if(Col.tag == "Player")
{
showPickUp = true;
}
if(Col.tag == "Player" && Input.GetMouseButtonDown(1))
{
StoneAxeInHandObj.SetActive(true);
Destroy(gameObject);
}
}
function OnTriggerExit (Col : Collider)
{
if(Col.tag == "Player")
{
showPickUp = false;
}
}
function OnGUI ()
{
if(showPickUp == true)
{
GUI.contentColor = Color.red;
GUI.Label(new Rect(650, 650, 200, 50), "Right click to pick up a StoneAxe", style);
}
}