- Home /
How can I make the script to play with the mouse?
I would like to make the script in C# to make the player move the object(hand) as it can be seen in the game Surgeon Simulator. I've tried several ways but I can't make it work.
In questions like this one, it is helpful for you to post your script attempts, and the clearer you can be about the motion you are seeking the more likely you are to get a good answer.
A mouse is a 2D device, the hand is the video is moving in 3D plus there is rotation, and finger movements. If you just mean move on the XZ plane, here is a script to get you started:
var speed = 0.5;
function Update () {
transform.position += Vector3(Input.GetAxis("$$anonymous$$ouse X"), 0.0, Input.GetAxis("$$anonymous$$ouse Y")) * speed;
}
hey, thanks for answering. I've tried the code but I get the error "Expression denotes a 'type', where a 'variable', 'value' or 'method group' was expected". Trying I figured out it can be solved like this:
public float speed = 3;
void Update(){
transform.position += new Vector3(Input.GetAxis("$$anonymous$$ouse X"), 0.0f, Input.GetAxis("$$anonymous$$ouseY")) * speed;
}
I have no idea about the error. You would get that error if you did not have the 'new' keyword. Any chance the file wasn't saved? Here is the C# version (which is the same as your lines, but I did test this exact script).
using UnityEngine;
using System.Collections;
public class Hand$$anonymous$$ovement : $$anonymous$$onoBehaviour {
public float speed = 0.5f;
void Update () {
transform.position += new Vector3(Input.GetAxis("$$anonymous$$ouse X"), 0.0f, Input.GetAxis("$$anonymous$$ouse Y")) * speed;
}
}