if (Input.GetButtonDown("Fire1"))
Instantiate(newObject, transform.position + transform.forward * 2.0 , transform.rotation);
after instantiating i want the object to stay in front of my player while i am walking around, then when i want to drop it i will click the mouse again. i think i have to use something like:
Since you only posted some snippets of your code I can't really figure out what exactly you're doing wrong, but i guess you work on the wrong object. Instantiate takes as first parameter a object that should be cloned (can be a prefab). The function returns the new created clone.
Also it’s not clear to which object your script is attached. If it’s attached to the player don’t use FindWithTag it’s not necessary. So your script could look like:
var newObjectPrefab : GameObject; // Assign object prefab to this var
private var currentObject : GameObject = null;
function Update()
{
if (Input.GetButtonDown("Fire1"))
{
if (currentObject == null)
{
currentObject = Instantiate(newObjectPrefab, transform.position + transform.forward * 2.0 , transform.rotation);
currentObject.transform.parent = transform;
currentObject.rigidbody.isKinematic = true;
} else
{
currentObject.transform.parent = null;
currentObject.rigidbody.isKinematic = false;
currentObject = null; // To be able to spawn another one
}
}
}