I need to make Bullet Velocity when I press the mouse 0 button but the bullet keeps dropping instead of going forward. This is my code
var bulletPrefab : Transform;
var Spawn : Transform;
var bulletSpeed : int;
function Update() {
if (Input.GetKeyDown("mouse 0")){
Debug.Log("Left mouse has been pressed");
Fire();
}
}
function Fire (){
var BulletPrefab = Instantiate(bulletPrefab, Spawn.position, Spawn.rotation);
bulletPrefab.rigidbody.AddForce(transform.forward * bulletSpeed);
}
error code -
InvalidCastException: Cannot cast from source type to destination type.
gunShoot.Fire () (at Assets/Custom Scripts/gunShoot.js:14)
gunShoot.Update () (at Assets/Custom Scripts/gunShoot.js:9)