Trigger picked up by everyone

How do I make a trigger only be picked up by one object?

Thanks,
-Mike

check if it is the right object within the OnTriggerEnter(…) function of the MonoBehaviour you assigned or in the handling code of the object that would pick it up

I’ve tried

var Player : GameObject;
function OnTriggerEnter(Player) etc

it works, but when I shoot the trigger it also trips.

Thanks,
Mike

Hi

Regarding the 2nd problem, this might help: Unity - Scripting API: Physics.IgnoreCollision I personally haven’t tried it with OnTriggerEnter(hit : collider)

Cheers

could you please post the corresponding script.
using trigger alone won’t help you have to check whats entering the trigger.

above code makes no sense as you are just defining it there as local variable that has no relevance or relation to the defined player variable

I set what the “Player” variable is in the inspector.
But when I shoot the Bomb it also triggers.

var Player : Transform;
var BombObject : GameObject;

function OnTriggerEnter(Player){
	BombTracker.bombs = 1;
	Destroy(BombObject);
}

thats because you don’t check if it is the player.

you can not just use the same variable name and then expect it to happen just for that object I fear. You are actually “killing” the direct access to the Player variable that way.

The correct code would be:

var Player : GameObject; 
var BombObject : GameObject; 

function OnTriggerEnter( other : Collider){ 
   if( collider.gameObject != Player )
      return;

   BombTracker.bombs = 1; 
   Destroy(BombObject); 
}

This simple thing is driving me crazy. I used you’re code and it doesn’t pickup at all now.

hmm.

Thanks,
-Mike

Sure you assigned the player object within the scene as it is at runtime, that you didn’t assign its prefab or alike?

because with prefabs it wouldn’t work.

if you want to use prefab assignements, you would have to add .tag on both sides and give your player a unique tag

bergerbytes: Can you provide more information regarding the different gameobjects you have inside your scene and in particular what gameobject is that script (outlined above) attached to.

I’m assuming you have a player bomb gameobject(s)? do they have colliders attached to them, have you set one of them to be a trigger and attached a ridgidbody to the other? Do you set tags for each kink of object particularly for the bomb objects.

Cheers

the collision setup obviously works as he had all other things picking it up before :slight_smile:

Yeah, I have no idea what was going on. I still couldn’t get it to work. I finally got a “alternate” way to do this. I know it’s more complicated but it works.

var Player: Transform;

function Update () {
	
	if(Player != null)
	{
	if(Player)
	{
		var dist = Vector3.Distance(Player.position, transform.position);
		Debug.Log(dist);
	}
	
	if( dist  < 11)
	{
		BombTracker.bombs++;
	    Destroy(this.gameObject);
	
	}
	}
	
}

Thanks,
-Mike