instantiating prefab with translation and rotation.

Hi, I’m just trying to make a portal graphic instantiate behind a door a few seconds after the door is triggered to open by the player.
I’ve got the Vector 3 coordinates and the rotation at which I want the prefab to appear in the scene.
The end of the code is a mess, but it sort of shows what I’m trying to do. I’ve been trying to find tutorials on YouTube to work out the correct way to write it.
Any feedback would be great.

using UnityEngine;
using System.Collections;

public class DoorScript1 : MonoBehaviour
 



{
    GameObject MockronDoor1;
    public GameObject portal;
   
    void Start ()
    {
        MockronDoor1 = GameObject.Find ( "MockronDoor1" );
    }
   
    public void OnTriggerEnter ( Collider other )
    {
        if ( other.tag == "Player" )
        {
            MockronDoor1.animation.Play( "Door1OPEN" );
            yield WaitForSeconds ('3');
            Instantiate(portal, transform.Translate(Vector3(-47,38, -139)), transform.Rotate (Quaternion(-11,138,91));

        }
    }
}
Instantiate (portal, Vector3 (-47, 38, -139), Quaternion.Euler (-11, 138, 91));

The following link explains instantiate. It doesn’t cover Quaternion.Euler, but that’s what you would use to provide vector3 style coordinates for rotation. http://docs.unity3d.com/412/Documentation/ScriptReference/Object.Instantiate.html

If you assign the whole line to a variable you can then reference the object you instantiated so you can manipulate it, like so:

GameObject myObject;
myObject = Instantiate (portal, Vector3 (-47, 38, -139), Quaternion.Euler (-11, 138, 91));
1 Like

I really appreciate that. I’ll copy all this information and never forget it.