I’m new to unity and C#, I can’t figure out what to do from here… I know it’s nothing…
void Update () {
var MouseX = Input.mousePosition.x;
var MouseY = Input.mousePosition.y;
transform.Translate(1f*Time.deltaTime,0f,0f);
}
I’m new to unity and C#, I can’t figure out what to do from here… I know it’s nothing…
void Update () {
var MouseX = Input.mousePosition.x;
var MouseY = Input.mousePosition.y;
transform.Translate(1f*Time.deltaTime,0f,0f);
}
You’re just storing the mouse position but you’re not using it in your translate function. What your code is doing is just moving your character in positive x, and that’s not what you want.
You can use a function like this one instead:
public float speed = 0.2; //change this in the inspector to make it move faster
public bool somethingHappens = false; //If this is set to true your character will follow the mouse, use this as a switch to stop it or get it moving.
void Update() {//We use update since this way the function will run every frame
if (somethingHappens){ //if the character should follow the mouse
float step = speed * Time.deltaTime; //set the step using the speed and the game's clock
transform.position = Vector3.MoveTowards(transform.position, Input.MousePosition, step);} //move from the current position to the mouse position at the desired speed
}
So whenever you want the character to follow the mouse, you set somethingHappens = true;
and it shall do so.