I am making a survival game and i have a problem.
I made it so the way you pick up items needs to remember a gameobject because the script is on the item itselft, but when i instantiate the object it doesnt remember that gameobject.
How do i fix this?
(I dont know everything about scripting yet)
script for the object “stick” :
private bool Collect;
public GameObject gameobject;
private Inventory inventory;
void Start()
{
inventory = gameobject.GetComponent<Inventory>();
Collect = false;
}
void Update()
{
if (Collect == true)
if (Input.GetButton("pickup"))
{
inventory.sticks += 1;
Destroy(gameObject);
}
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.name == ("collector"))
{
Collect = true;
}
}
void OnTriggerExit(Collider other)
{
if (other.gameObject.name == ("collector"))
{
Collect = false;
}
}
(collector is a dot in the middle of the screen that has a long block collider and is attached to the camera)