Im trying to make a simple arcady like game but im having trouble with the projectiles. About half the time they shoot like they should and the other half the shoot from below the player. Cant figure out why, heres my scripts:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class shooting : MonoBehaviour {
public bool isFiring;
public shot bullet;
public float bulletSpeed;
public shooting theGun;
public float timeBetweenShots;
private float shotCounter;
public Transform firePoint;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButtonDown(0))
theGun.isFiring = true;
if (Input.GetMouseButtonUp(0))
theGun.isFiring = false;
if (isFiring)
{
shotCounter -= Time.deltaTime;
if (shotCounter <= 0)
{
shotCounter = timeBetweenShots;
shot newBullet = Instantiate(bullet, firePoint.position, firePoint.rotation) as shot;
newBullet.speed = bulletSpeed;
}
} else
{
shotCounter = 0;
}
}
}
my other script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class shot : MonoBehaviour
{
public float speed = 5f;
void Start()
{
}
void Update()
{
transform.Translate(Vector3.forward * speed * Time.deltaTime);
}
}