- Home /
Take object from player
I have a store and the player brings object to the store. If the player brings 3 objects than the store takes 3 objects. If the player has 2 then the store takes two. And leaves the player with 0. Is there a clue as to how to script this?
public int storing = 0; PlayerInfo info;
void Start()
{
info = GetComponent<PlayerInfo>();
}
void OnTriggerEnter (Collider other)
{
if (other.gameObject.tag == "Player")
{
if (info.holding > 1)
{
storing +=info. holding;
info.holding = 0;
}
if (info.holding <= 0)
{
Debug.Log ("nothing to take");
}
}
}
I only know the very basics of Unity and this was the best i could think of, but its appears to be wrong because nothing is showing up... holding and storage are both public ints, I'm not sure if this is the ideal way of collecting items. But it was the simpliest i could think of...
Hard to tell what's wrong only seeing this part of the code, but did you mean to do "info.holding >= 1"? The way you have it set up, nothing will happen if the player goes to the store with only 1 item.
Try adding more debug's to see where things stop working. Is OnTriggerEnter
ever called? Is the value of info.holding
0 all the time?