0
votes

I'm rather new to Unity and trying to get started with a simple scene consisting only of an FPS Controller and a few obstacles. As the controller I'm using the one from the Unity Standard Assets and everything worked fine. Upon adding a Character Mesh however I noticed that I had to setup camera clamping. The controller script accesses the serialized "MouseLook" script in which I have to edit a few variables to fit my needs. Since it's serialized however I can't simply change the variables, save the code and get the changes. Since I'm not planning on changing the fact that the script is serialized I just want to update my changed variables.

I hope this was understandable. Thanks in advance!

1
Try changing the values in the inspector, rather than in the code. - Draco18s no longer trusts SE

1 Answers

0
votes

Hello and welcome @Corneey,

For starters, I have no idea how to recompile that script or change any values (except for some input fields it might have?), but there's a workaround:

public class LookAtMouse : MonoBehaviour
{
    //The object to rotate with/look at the mouse
    public Transform target;

    //Update is called once per frame
    public void Update()
    {
        //Get mouse position in 3D space
        Plane target = new Plane(Vector3.up, 0);
        Ray r = Camera.mainCamera.ScreenPointToRay(Input.mousePosition);
        //On the hit, rotate the target to the "impact point"
        if(target.Raycast(r, out float distance)
            Vector3 hitPoint = r.GetPoint(distance);
    }
}