Hi i am trying to make it so i can pick up different things.
I made it so i have a raycast that check if i am pointing on the object and and if i am in range and so far. The problem is i want to add a lot of items that i can pick up. The player should not be able to carry more then one item at a time so i will not be using any inventory, I so far made it so i can pick up the one item, ive added so far but i want to be abel to pick up any item with out writing a if statement about every pice of item. Any ideas ?
One good way would be if the raycast could tell me what item i hit and then go forth from there and just tag items that would be possible to pick up. But struggle to know if i can tell me what i have hit. I am slightly new to raycasts class .
function Update ()
{
var fwd = transform.TransformDirection (Vector3.forward);
var hit : RaycastHit;
var dist = 5;
if (Physics.Raycast (transform.position, fwd, hit,dist))
{
if(hit.collider.gameObject.tag == "axe")
{
//print("Axe is in sight");
if(Input.GetKey(KeyCode.E))
{print("Trying to take upp axe");
var axe = GameObject.Find("axe");
// here i will put in some code to get the item to apear where my hand are atm. But sens i saw a flaw here i did not continue
DestroyObject(axe);
}
}
}
}