Im making an pickup objects system, in which the player should be able to pick up an item with a specific tag and when it is picked up, something will happen ex. when u pick up food your health gets higher.
here is my code;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class pickup : MonoBehaviour
{
float maxDistance = 20;
public GameObject target;
void FixedUpdate()
{
// Will contain the information of which object the raycast hit
RaycastHit hit;
// if raycast hits, it checks if it hit an object with the tag tag
if(Physics.Raycast(transform.position, transform.forward, out hit, maxDistance) && hit.collider.gameObject.CompareTag("tag") && Input.GetKey (KeyCode.E))
{
target.SetActive (false);
}
}
}
and the thing that can be picked up will have a code that runs when the object is deactivated.
My problem is that right now i can just have one object that can be picked up (the target), id like to have it so that anything with that tag, or any child in a game object can be picked up without influencing the other objects in that game object. Please answer!
P.S. Sorry for bad english.