Spawning portal

I have a prefab called portal and I want to make it so that when my player press the P button it makes a portal appear infront of them. I would like to make it so that it is a little infront of them that way you dont instantly go though it.

I have tried this but it never spawns my object.

var prefab : Transform;

if(Input.GetKey(KeyCode.D)) {
Instantiate (prefab, Vector3(2.0, 0, 0));

Ok, a couple of problems here. Check the instantiate command first :

Instantiate (original : Object, position : Vector3, rotation : Quaternion) : Object 

it says you need to provide an object, a position and a rotation. The easiest way to do this is :

Instantiate( original , transform.position, Quaternion.identity );

this will clone ‘original’ at the position and at a rotation of zero.

to make something be 2 units in front of something, use this formula :

transform.position + (transform.forward * 2.0)

put it all together and you have :

#pragma strict

var prefab : Transform;

function Update () {
	if( Input.GetKeyDown(KeyCode.D) ) 
		Instantiate( prefab, transform.position + (transform.forward * 2.0), Quaternion.identity );

And as I said in my comment, you can Instantiate into many types =]