Creating an instance at a position based on rotation

Hi, I have this script that will create an instance of a bullet prefab at the objects position plus some offset.
The script

var newObject : Transform;
var timer = 0;
function Update () {
	if (Input.GetButton("Fire1")){
		if (timer == 0){
			Instantiate(newObject,
                     Vector3(transform.position.x+.2,
                     transform.position.y+.7,transform.position.z+.8),
                     transform.rotation);
			timer = 5;
		}
	}
	if (timer > 0){
        timer --;
    };
}

It creates the bullet, but if you rotate the character to move, the bullet will be created at the wrong point, behind the character instead of in front.
So, how would I change the bullets position based on the rotation of the character for it to be created at the right point?

For the position, use transform.TransformPoint(Vector3(.2, .7, .8)).

You have set the position as a fixed offset, so when the character rotates the object is created at the same offset you’ve specified, no matter which direction the character is turned to. You must create the spawn point as a Vector3, then use transform.rotation to rotate the point with the character:

var newObject : Transform;
var timer: float = 0;
var spawnPoint = Vector3(0.2,0.7,0.8);

function Update () {
  if (Input.GetButton("Fire1")){
    if (timer <= 0){
      var p = transform.rotation * spawnPoint;
      Instantiate(newObject, transform.position + p, transform.rotation);
      timer = 0.2;
    }
  }
  if (timer > 0){
    timer -= Time.deltaTime;
  }
}

You can think of spawnPoint as a vector. When it’s multiplied by the quaternion transform.rotation, it assumes the same rotation as the character.
Since I’m a very nosy guy, I couldn’t resist and also changed your timer: now it takes 0.2 seconds to enable shooting again. Counting frames as you did is not reliable, because the frame rate can vary a lot.

Personally, I like having spawn points for things that I’ll be instantiating on a regular basis.

  1. Create game object with only a transform
  2. place it where you want it in relation to your character
  3. make it a child of your character (to be affected by translations/rotations, etc)
  4. instantiate your bullets from it’s now-properly positioned/rotated location