Hello. I am fairly new to Unity 3D and I am starting a project. The player crafts an item and as soon as it’s crafted, the item falls to the ground. I want to attach a script to that object that OnTriggerEnter it destroys the object that has been created and re-instantiates the object in the hands of the player and when it is instantiated, it sets the hand of the player as the parent of the object. PLEASE TAKE NOTE:
This is my script being attached to the prefab (The object is a knife)
var InventorySystem: Inventory;
var SpawnPosition: Transform;
function Start()
{
InventorySystem = GameObject.Find("3rd Person Controller").GetComponent(Inventory);
SpawnPosition = GameObject.Find("AltItemPos").transform;
}
function OnTriggerEnter(Col:Collider)
{
if (Col.tag == "Player")
{
InventorySystem.itemEquipt();
}
}
And this is the function: itemEquipt() and the variables it uses
var knife: Transform;
function itemEquipt()
{
Destroy(PickUpScript.gameObject);
Instantiate(knife, PickUpScript.SpawnPosition.position, PickUpScript.SpawnPosition.rotation);
}
//How do I instantiate it and make it the child of SpawnPosition?
THANK YOU!