I am trying to spawn a fireball whenever the ‘F’ key is pressed, but every time I press the F key, the fireball spawns at a different place on the Y-axis. Any thoughts?
Player Attack Script
using UnityEngine;
using System.Collections;
public class PlayerAttack : MonoBehaviour {
public float attackTimer;
public float coolDown;
public float damage;
public Rigidbody projectile;
public float speed = 0.1f;
Rigidbody fireball;
public Transform fireBallSpawn;
void Start () {
attackTimer = 1;
coolDown = 0.5f;
damage = 5.0f;
}
void Update () {
if (attackTimer > 0) {
attackTimer -= Time.deltaTime;
}
if (attackTimer < 0) {
attackTimer = 0;
}
if (Input.GetKeyUp(KeyCode.F))
{
if (attackTimer == 0) {
Attack();
attackTimer = coolDown;
}
}
}
private void Attack() {
fireball = Instantiate(projectile, fireBallSpawn.position, fireBallSpawn.rotation) as Rigidbody;
fireball.velocity += transform.forward * 5;
Destroy(fireball.gameObject, 2.0f);
}
}
At the bottom of the screen, the console is printing the y-axis for the spawner.