hit object to turn invisible

I have 5 objects in my game that I am going to be picking up and counting when one has been picked up. I am unsure how to make the object turn invisible when it’s been hit so it looks like it has been picked up. I guess I just put a mesh collier on the object then add the code to the first person controller?

2 Answers

2

You can either use gameObject.active = false, which disable every components, or disable only the renderer, with renderer.enabled = false; Now you just need to do that on the right object at the right moment.

If you’re wanting it to turn invisible when it’s picked up, you could use a trigger.

	public GameObject thing;
	public GameObject dropArea; // if you're wanting to drop items also at some point
	
	void OnTriggerEnter() // You put this script on a Cube, turn the material off and  //tick the "is trigger" box
	{
		if(Input.GetKey(KeyCode.E))
		{
			thing.transform.position = dropArea.transform.position;
			thing.active = false;
		}
	}
}