I did the changing projectile direction differently, I put the logic in the PlayerMovement script
bool FacingLeft{
get{
return transform.localScale.x<0;
}
}
void OnFire(InputValue value)
{
var fireballProjectile = Instantiate(fireballPrefab,handPosition.position,handPosition.rotation);
var fireballComponent = fireballPrefab.GetComponent<Fireball>();
if(FacingLeft)
{
Debug.Log("Fireball to left");
var scale = fireballProjectile.transform.localScale;
fireballProjectile.transform.localScale = new Vector3(scale.x * -1,scale.y,scale.z);
fireballComponent.fireballSpeed = -fireballSpeed;
}
else
{
Debug.Log("Fireball to right");
fireballComponent.fireballSpeed = fireballSpeed;
}
}
This almost works, but the first time I fire after switching direction the fireball moves backwards (but the facing of the fireball is correct). Here’s a screenshot. I was facing left, turned to face right, then clicked twice. The fireball on the left of me is the one that spawned first, it’s facing right as it should be, but moving backwards.
I presume that it would work if I did it the same way as in the video, but I’d like to understand what’s going on here.