How can I deactivate game objects by touching them with the player ?

Hi i am working on the roll-a-ball tutorial project but the pick up objects dont deactivate or disappear when the player gets in touch with them, although i put everything in my script and tagged the player with PickUp. Does anyone knows a possible reason for that ? Thanks

using UnityEngine;
using System.Collections;

public class PlayerController : MonoBehaviour
{
public float speed;

void FixedUpdate ()
{
	float moveHorizontal = Input.GetAxis("Horizontal");
	float moveVertical = Input.GetAxis("Vertical");

	Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);

	rigidbody.AddForce(movement * speed * Time.deltaTime);
}
void OnTriggerEnter(Collider other) 
{
	if(other.gameObject.tag == "PickUp")
	{
		other.gameObject.SetActive(false);
	}
}

}

Hi,

I might be missing something here, but it seems as if you are checking for the wrong tag in your OnTriggerEnter.

You said that you tagged the player with pick up, but you still check for the PickUp tag in your OnTriggerEnter. Shouldn’t you be tagging your objects that you are picking up as PickUp?

What OnTriggerEnter does is check when the player enters a trigger (which I’m assuming your objects are), and then executes code. So, the other gameobject is going to be set to the object you want to pick up. What you are currently doing is checking wether the object being picked up has the same tag as the player, which presumably it doesnt, so, try switching your tags around.

Otherwise the script looks fine to me,

Hope that helps,

Good Luck :slight_smile:

IEMatrixGuy