I'm trying to make an object in-game follow the mouse, using the mouse sort of like an analogue stick, although I wouldn't say I'm very far along with it I've run into a problem I can't seem to figure out already.
Here's the code:using System.Collections;using System.Collections.Generic;using UnityEngine;
public class FemaleActor : MonoBehaviour
{private bool inMotion;
void Start(){float mousePosX = 0f;float mousePosY = 0f;}
void Update(){var x = Input.GetAxis ("Mouse X");var y = Input.GetAxis ("Mouse Y");
float mousePosX = x + mousePosX;float mousePosY = y + mousePosY;
transform.position += new Vector3(0f, mousePosY, mousePosX) * Time.deltaTime;}}
And here's the error:
The variable 'mousePosX' is assigned but its value is never usedThe variable 'mousePosY' is assigned but its value is never used
Use of unassigned local variable 'mousePosX'Use of unassigned local variable 'mousePosY'
The particular problem is the ‘use of unassigned local variable’ compiler error. As you can see the warnings are contradictory, mousePosX and mousePosY are assigned the value of 0f in Start() but when called upon in Update() it's like the assignment has been forgotten even when it, as far as I know, shouldn't be.