hi,
I’m kind of new to Unity scripting so I’m sure there is a simple solution to this. The problem is when my spaceship gets a mouse click, it waits like 10 seconds to instantiate the bullet, and then, it shoots in the wrong direction. I have no idea waht to do. Here’s my code, hope you can help.
`#pragma strict
var ship : Transform;
var cannon : Transform;
var speed : float = 60.0f;
var rotationSpeed = 100.0;
var bulletSpeed : float = 100f;
var Bullet : Rigidbody;
var gravOfHoleRot = 1;
var drift : float = 0.2;
function Start () {
}
function Update () {
var rotation = Input.GetAxis(“Horizontal”) * Time.deltaTime * rotationSpeed;
var movement = Input.GetAxis(“Vertical”) * Time.deltaTime * speed;
ship.Translate(movement, 0, 0);
ship.Translate(drift,0,drift);
ship.Rotate(0,rotation,0);
ship.Rotate(0,0,0);
if(Input.GetButtonDown("Fire1")){
// Instantiate the projectile at the position and rotation of this transform
var clone : Rigidbody;
clone = Instantiate(Bullet, cannon.transform.position, cannon.transform.localRotation);
// Give the cloned object an initial velocity along the current
// object's Z axis
clone.velocity = cannon.TransformDirection (Vector3.forward * bulletSpeed);
}
}`
And just for the record, this is pretty much copy and pasted from the unity manual. Sorry about the code format, its all messed up.