Parenting Instantiated Objects

Pretty simple question.

Is there a way to instantiate an object and attach it to a Player Object? We are doing a RPG and I have a plane with texture for magic casting. Now it spawns and does everything correct, however if the player moves while doing it, it doesn't move like I'd like even with the code I have. So my question is, can I instantiate an object and attach it to the Player Object? This would fix the object as it would move according to the Player setup.


By object, I presume you mean GameObject, and not Component (which would require AddComponent()). If you're instantiating a new GameObject, and want to set its parent to another GameObject, what you would do is just set the parent property to the owner object's transform:

public GameObject prefabThing; // drag/drop a reference to the object.

GameObject newThing = (GameObject) GameObject.Instantiate(prefabThing);

newThing.transform.parent = PlayerGO.transform;