marcrasmussen
New member
I have attempted to create a static turrent that fires a projectile:
When this code is executed on enable (the first time) a projectile is fired however when running the update code the projectile just stands still and doesnt move.
Can anyone see what ive done wrong?
Code:
[SerializeField] public GameObject m_projectile;
public Transform firePoint;
private GameObject m_SpawnedProjectile;
private void OnEnable()
{
var rotation = Quaternion.LookRotation(transform.forward);
m_SpawnedProjectile =
ObjectPoolBase.Instantiate(m_projectile, firePoint.position, rotation * m_projectile.transform.rotation);
var projectile = m_SpawnedProjectile.GetCachedComponent<Projectile>();
projectile.Initialize(Vector3.forward, Vector3.forward * 200, gameObject);
m_SpawnedProjectile = null;
}
private void Update()
{
if (Input.GetKeyUp(KeyCode.X))
{
var rotation = Quaternion.LookRotation(transform.forward);
m_SpawnedProjectile = ObjectPoolBase.Instantiate(m_projectile, firePoint.position,
rotation * m_projectile.transform.rotation);
var projectile = m_SpawnedProjectile.GetCachedComponent<Projectile>();
projectile.Initialize(Vector3.forward, Vector3.forward * 200, gameObject);
}
}
When this code is executed on enable (the first time) a projectile is fired however when running the update code the projectile just stands still and doesnt move.
Can anyone see what ive done wrong?