- Home /
Question by
CB-TV · Jul 09, 2013 at 04:45 PM ·
gameobjectraycastmouseinventory
Raycast To Collect Items
I have a script which I want to use a raycast to go and only let me get the items when I am in a certain position. I have a script and I'm not sure how to work it:
#pragma strict
var TheDamgage : int = 50;
var Distance : float;
function Start () {
}
function OnMouseDown ()
{
if (gameObject.name == "Stick")
{
var hit : RaycastHit;
if (Physics.Raycast (transform.position, transform.TransformDirection(Vector3.forward), hit))
{
PlayerInventory.itemPlayerAmount[0] += 1;
InventoryAddItem.InventoryNewItemAdded = 0;
Distance = hit.distance;
hit.transform.SendMessage("ApplyDammage", TheDamgage, SendMessageOptions.DontRequireReceiver);
Destroy(gameObject);
}
}
}
I tried adding in function Update at the top but it doesn't work. I know I may have put them in the wrong order or I need to add something else in-does someone know how to do it?
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613105758im_/https://answers.unity.com/themes/thub/images/avi.jpg)