do something if i right click

Hi …
I’m trying do the following :
If I pressed Right Click and object 1 collision object 2, object 2 change its position
I used this code but object 2 change its position even not collide object 1

var FirstHit : Transform; 
var touch : boolean = false;

function OnCollisionEnter(collision : Collision) 
{ 
    if(FirstHit==null) 
       FirstHit = collision.transform; 
} 
function Update() 
{ 
if(FirstHit != null  Input.GetMouseButtonDown(1)) 
{
transform.position = FirstHit.position + Vector3.up; 
touch = true;
}
}

where the mistake here ???

Maybe their colliders are overlapping at the start of the game? Or maybe you set the firstHit variable to something before the start as well?

And also if it were me, I’d use GameObject, not Transform, as sometimes Unity gets confused as to which you’re trying to represent. So I’d try
var FirstHit : GameObject;
and
FirstHit = collision.gameObject;

And then of course you should look at the variable in the editor itself.

What’s that thing you start all your thread titles with? The Wikitionary/Wikipedia entries don’t make sense, as far as I can tell.

Thanks SomeGuy22 for your Polite reply ッ ッ ッ

That. Please explain it.

Jessy - I assumed it was a random katakana character he found that he thought looked like a smiley

Also WoodyGoody, the FirstHit variable should be private like I showed you in the other thread.

Otherwise you, or some one using the script could add something to that variable in the inspector, as the script is now, you don’t want that, it would make the object that script is in follow what ever is assigned to it in the inspector.

Also, you could use the touch variable you added instead, probably better down the road any way if you want to have other collisions or the ability to drop the object your carrying. If you do that though, just get rid of the FirstHit==null and FirstHit!=null and replace them with !touch and touch, respectively.

Thanks for all, That is Japanese letter looks like smile ッ sorry if this make confused