hi everyone, im pretty new to all of this and i need some help. in my project i want to have an object in the map and when the player left clicks on it, it dissapears and a notice comes on screen to say “picked up data number x/12” how do i script this?, like i said im new so if you could explain it as simply as possible i would be very appreciative thanks!
If you are using C#, you could use the following:
- Make sure there is a Collider attached to your object
- Add a script to the object
- In that script, add the following code:
void OnMouseDown(){ // Detects if the mouse is clicked within the collider bounds, it only triggers when this is true.
Destroy(this.gameObject); // Destroys the gameObject to which this script is attached
Debug.Log("You have picked up an item"); // Log a debug message
}
- ???
- Profit
Use Physics.Raycast to check when mouse down
var c = 0
function Update() {
if(Input.GetMouseButtonDown(0))
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hit : RaycastHit;
if(Physics.Raycast(ray,hit,100))
{
c += 1;
Debug.Log(“picked up data number “+c as string+”/12”);
}
}