- Home /
Question by
Razion · Feb 01, 2013 at 02:58 AM ·
cameraplayeronmousedown
Reference to Camera/Player that initiates OnMouseDown
Trying to work on an inventory system where a player triggers an OnMouseDown event on an object which calls an inventory.AddItem method to add said object to a players inventory (attached to the gameobject that initiated the OnMouseDown call).
Is there any way to refer to that initator? As it stands I have no way of telling the item which players inventory it belongs in.
Thanks in advance!
Comment
Answer by Imankit · Feb 01, 2013 at 05:20 AM
using UnityEngine; using System.Collections;
public class example : MonoBehaviour {
RayCastHit hit;
void Update() {
if (Input.GetMouseButtonDown(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray,out hit))
{
if(hit.gameObject.name == "InventoryObject1")
{
//Do Something
}
}
}
}
}