So I'm making a platformer with shooting mechanics, and part of the game is that you fire around yourself and aim with your mouse.
This code works fine in Unity 2022.1.11f1, but in a more recent version (2023.1.5f1), Unity is telling me that "'Camera' does not contain a definition for 'ScreenToWorldPoint' and no accessible extension method 'ScreenToWorldPoint' accepting a first argument of type 'Camera' could be found (are you missing a using directive or an assembly reference?)"
And my google-fu is failing me, so... what gives? 'ScreenToWorldPoint' didn't stop being a thing, did it?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MoveFirePoint : MonoBehaviour
{
private Camera mainCam;
private Vector3 mousePos;
// Start is called before the first frame update
void Start()
{
mainCam = GameObject.FindGameObjectWithTag("MainCamera").GetComponent<Camera>();
}
// Update is called once per frame
void Update()
{
//Follow mouse
mousePos = mainCam.ScreenToWorldPoint(Input.mousePosition);
Vector3 rotation = mousePos - transform.position;
float rotZ = Mathf.Atan2(rotation.y, rotation.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.Euler(0, 0, rotZ);
}
}
I've googled this issue and find six or seven different "solutions" that all cover what to do when this centers your firing indicator in the wrong place. The issue I'm running into is that the compiler doesn't recognize the command.