So I’m very new to unity so I don’t really understand a lot, I’ve been working on a game and mouse position, or at least the code I have for shooting, seems to be screwed up in some way in builds of the game, but not in unity, and it’s very frustrating. Here is a video to explain better:
The code I am using is:
using UnityEngine;
public class shooting1 : MonoBehaviour
{
public GameObject bullet;
public Transform firePoint;
public float bulletSpeed = 50;
public Transform playerPos;
public Vector2 lookDirection;
public float lookAngle;
public float fireRate;
public float fireDelay;
public PlayerController PlayerController;
public bool facingRight = true;
public GameObject GunSound;
void FixedUpdate()
{
if (0 < lookDirection.x && facingRight == false)
{
flip();
}
else if (0 > lookDirection.x && facingRight == true)
{
flip();
}
}
void Update()
{
if (!PauseMenu.isPaused)
{
lookDirection = Camera.main.ScreenToWorldPoint(Input.mousePosition);
lookDirection = new Vector2(lookDirection.x - transform.position.x, lookDirection.y - transform.position.y);
lookAngle = Mathf.Atan2(lookDirection.y, lookDirection.x) * Mathf.Rad2Deg;
firePoint.rotation = Quaternion.Euler(0, 0, lookAngle);
if (Input.GetMouseButton(0) && fireDelay <= 0)
{
GameObject bulletClone = Instantiate(bullet);
bulletClone.transform.position = firePoint.position;
bulletClone.transform.rotation = Quaternion.Euler(0, 0, lookAngle);
bulletClone.GetComponent().velocity = firePoint.right * bulletSpeed;
fireDelay = fireRate;
GameObject gunSoundClone = Instantiate(GunSound);
gunSoundClone.transform.position = firePoint.position;
}
if (fireDelay > 0)
{
fireDelay -= Time.deltaTime;
}
}
}
void flip()
{
facingRight = !facingRight;
Vector3 Scaler = transform.localScale;
Scaler.y *= -1;
Scaler.x *= -1;
transform.localScale = Scaler;
}
}
Sorry if this is the wrong place to post this, I’m very new to unity. If anyone knows why this would be happening, then please share, I don’t have extra monitors or anything if that matters, just the one.