getting .Transform from instanntiated object

I’ve been looking at the code for clicking on a game object by using ray cast here http://forum.unity3d.com/threads/31708-Detecting-an-object-from-a-point-on-the-screen

my only issue is the objects are instantiated, they’re in variables upon instantiation, I’m just curious if anyone can tell me is there any way to call upon the Transform of an object through scripting so this method works?

I think the methods I’ve tried that spat it back out were .Transform and .GetComponent(Transform).

also just as an extra query whilst I’m referring to getting information from game objects. Is it possible for a specific game object to check if it is the object in a GameObject variable?

I don’t fully get what you are asking in the first part of your question, since andeeee’s example script doesn’t contain any object references, except in the “hit” structure returned by Physics.Raycast.

To access the transform of the GameObject your script is attached to, you can use gameObject.transform, or even just transform:

void Start(){
    print("My world position is "+transform.position);
}

If you have a GameObject in a variable - no matter whether it’s instantiated, assigned in the Inspector, or even found using scripted means (such as GameObject.Find(…)), the transform is accessed the same way: myVariableNameContainingTheObject.transform

For the second part of your question, the GameObject a script is attached to can be accessed via “gameObject”. So you can simply compare this to other GameObject variables:

if(gameObject==myVariableNameContainingTheObject)
    // do something

Note, everything is case sensitive, so .Transform won’t work, use .transform

var hit: RaycastHit;
var newThing;

if (Physics.Raycast(ray, hit)) {
    newThing = Instantiate(prefab, hit.point, Quaternion.identity);
    var pos = newThing.transform;

}