Instantiate a prefab to a Parent?

I have a game object as a parent and gui texture as its child.

I want to put a particle(named Hint) in a game object(parent of gui texture) when i clicked the gui texture. since its positioning is ruined because of the parent-child relation.

this is my code...


var Hint: GameObject;

function OnMouseOver() {

if(Input.GetMouseButtonDown(0)) {
Instantiate(Hint, transform.parent.gameObject.position, Quaternion.identity);
}

}


it display this message : "'position' is not a member of 'UnityEngine.GameObject'. "

can anyone help me? x.x

Position is a member of Transform. So you can access the parents position using this: transform.parent.position

However in my experience having GUITextures as children of other objects isn't a good idea, at least if the parent is supposed to move around as GUITextures use ScreenCoordinates and everything else is in local Coordinates.

You'll just want to do this:

var Hint: GameObject;
var parentOfHint : Transform;

function OnMouseOver() {

    if(Input.GetMouseButtonDown(0)) {
        var instantiatedHint = Instantiate(Hint, transform.position, Quaternion.identity);
        instantiatedHint.transform.parent = parentOfHint;
    }

}

In the script above, the parentOfHint is the Transform you want to parent Hint to. The second variable in the Instantiate function is actually where you want the object to be positioned upon creation, so you can't set its position at the same time, or Unity will get confused.

Please note that the above script is untested and may contain errors.

instantiatedHint.transform.localPosition = transformGameObjectToMatch.transform.localPosition;

try this

var Hint: GameObject;
var spawnpoint: Transform;
var HintParent: Transform;

function OnMouseOver() {

if(Input.GetMouseButtonDown(0)) {
var HintInsta: GameObject = Instantiate (Hint,spawnpoint.transform.position,Quaternion.identity);
HintInsta.transform.parent = HintParent.transform;
}
}