Hey guys, this is my first post on Unity Answers!
I’m having a little bit a trouble, on something I’m sure should be simple.
I have an Object (ObtainableObject) that should be picked up by the player, and then removed from the game world.
When the player move’s into it’s range, they are prompted to push the “pick up object” key, which will add +1 to the players Inventory Script value of “PickupObjectsHeld”…
However, I’m having trouble figuring out exactly how to reach that result…
I’v looked through several help threads, and I’v gotten closer to the answer, but not quite there yet…
Here’s my code for the Obtainable Object Class!
using UnityEngine;
using System.Collections;
public class ObtainableObjectScript : MonoBehaviour {
// Call from the Hierarchy
public GameObject thePlayer;
public Vector3 DistanceToPlayer;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
public void Update()
{
GameObject thePlayer = GameObject.Find("ThePlayer");
DistanceToPlayer = thePlayer.transform.position - transform.position;
if (DistanceToPlayer.magnitude < 10)
{
print("Pick Up");
if (Input.GetButtonDown("Use/Pickup"))
{
gameObject.Find("ThePlayer").GetComponent("ThePlayerInventory").pickupObjectsHeld+= 1;
Destroy(this);
}
}
}
}