Script creating 2 prefabs instead of 1
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Shoot : MonoBehaviour { public Camera playerCamera; public GameObject bulletPrefab;
public float roundRate;
public float timeToFire;
public float aboveTime;
void Start()
{
roundRate = 1.5f;
timeToFire = 0;
}
void Update()
{
timeToFire += Time.deltaTime;
if (Input.GetMouseButton(0) && timeToFire >= roundRate)
{
timeToFire = 0;
Debug.Log(timeToFire);
GameObject bulletObject = Instantiate(bulletPrefab);
bulletObject.transform.position = playerCamera.transform.position + playerCamera.transform.forward;
bulletObject.transform.forward = playerCamera.transform.forward;
}
}
}
If I move fast when firing, instead of the prefabs being created in the same spot, the are created just next to each other
prefab-duplication-problem.png
(320.5 kB)
Comment