Touch object.

Hello. I have this script:

(Physics.Raycast (ray, out hit, 200)) 		
		{
			Transform ObjectHit =  hit.transform as Transform;
			if (hit.collider.tag == "enemy")				
			{				
				//some code				
			}			
		}

With this I want to touch game object. And it is working, but the problem is that I have object of type “Transform”, not “GameObject” and that is not working. I want to apply that script to object that is created with this script

Transform clone;
clone = Instantiate (projectile, spawnPosition.position, spawnPosition.rotation) as Transform;

As you can see it’s “Transform”, not “GameObject” so this doesn’t work. Any way to get it work? :slight_smile:

Access the GameObject directly if you prefer: GameObject ObjectHit = hit.collider.gameObject;

I’m not sure how to do that. Can you explain it, I’m new to this.

I think you can’t achieve that.

Anyone? I tried your solution, but as I’m cloning object that has animations and it is spawning with Instantiate, so it has to be of type “Transform”.