- Home /
Make a GameObject child to a "Dragged Reference" GameObject doesn't work!
Hello everyone, I am having trouble making my instantiated prefab child of an another GameObject which is a dragged reference. I am dragging an object, and OnMouseUp() I am destroying it and Instantiating a new one at the desired position(giving the effect of being plotted) The object is being plotted on a sphere. Till here works fine, but I need to have the plotted object being child to the sphere.
I am rotating the sphere but the plotted object is not being rotated! Here's the code:
var Globe:Transform;
function OnMouseUp()
{
displayDefaultMouse = true;
Screen.showCursor = true;
if(isPlotted)
{
Destroy(currentPrefab);
var childToEarth:GameObject = Instantiate(smallPrefab,hit.point,Quaternion.FromToRotation(Vector3.up, hit.normal));
childToEarth.layer = 10;
childToEarth.transform.parent = Globe.transform; // not working
isPlotted = false;
}
}
Just checking that the globe hasn't been created at run time and is a scene object? Not a prefab...
I did the same thing, except that I didn't declare the var as a game object. For you it's like : var childToEarth = Instantiate(smallPrefab,hit.point,Quaternion.FromToRotation(Vector3.up, hit.normal)); Try this, There is no reason it would work better than your code, but it works in my project like that ...
Your answer
Follow this Question
Related Questions
Make a simple tree 1 Answer
Object scale/rotation changes when parented to flipped object 0 Answers
Moving parent to position of child 0 Answers
Problem with making child an object 2 Answers