I am trying to make the gun facing the mouse with this code
private void FixedUpdate()
{
if (view.IsMine)
{
mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
if (Input.GetButton("Fire1") && Time.time > nextTimeToFire)
{
GameObject bullet1 = Instantiate(bullet, firepoint.position, firepoint.rotation);
Rigidbody2D rb2 = bullet1.GetComponent<Rigidbody2D>();
rb2.AddForce(firepoint.right * 50f, ForceMode2D.Impulse);
ScreenManager.Instance.ScreenShake(10f, 0.1f);
Destroy(bullet1, 20f);
nextTimeToFire = Time.time + 1f/fireRate;
}
Vector2 lookDir = mousePos - rb1.position;
float angle = Mathf.Atan2(lookDir.y, lookDir.x) * Mathf.Rad2Deg;
transform.localEulerAngles = new Vector3(transform.rotation.x, transform.rotation.y, angle);
}
}
it worked before i was using photon but now it doesnt, anyone help