How do you set up two crosshairs that mirror each others movement?
Hey dudes! I'm working on a game where the character uses his arms to do things. These are directed by two crosshairs; one for the left arm and one for the right arm. My problem is that I'm trying to have the cursors mirror each others movements so that the left crosshair never crosses over to the right and vice versa (ex: if left crosshair is at x:-50, then the right is at x:50). I'm wondering if it would be better to script the two arms individually, or if I should have one script for both. Also, what would be the best way to go about that?
Thanks so much for the help!
UPDATE: I've decided to try creating the script for the canvas itself and calling the crosshairs individually. I don't really want to lock the mouse cursor on one side of the screen and rather would like the crosshairs to switch behaviours based on the mouse position. Here's the start of my code, but for some reason the right crosshair is being reflected off-screen:
public class Crosshair : NetworkBehaviour {
public float minX;
public float minY;
public float maxX;
public float maxY;
private Vector2 mousePos;
private float mousePosX;
private float mousePosY;
public Transform crosshairLeft;
public Transform crosshairRight;
void Start () {
if (!isLocalPlayer){
Cursor.visible = false;
mousePos = Event.current.mousePosition;
mousePosX = Input.GetAxis("Mouse X");
mousePosY = Input.GetAxis("Mouse Y");
}
}
void Update () {
if (mousePosX < -25){
crosshairLeft.transform.position = Input.mousePosition;
crosshairRight.transform.position = Vector2.Reflect(crosshairLeft.transform.position, Vector2.right);
}
else{
crosshairRight.transform.position = Input.mousePosition;
crosshairLeft.transform.position = Vector2.Reflect(crosshairRight.transform.position, Vector2.left);
}
}
}
I'm not very familiar with the vector2 reflect arguments, so I'm sure I botched that part.
Your answer
Follow this Question
Related Questions
How to aim at crosshair in a 2D game? 0 Answers
How to make gun shoot in the crosshair 0 Answers
Rotating UFOs to aim at target 0 Answers
Keep object within circle on plane 0 Answers
Mouse Pointer disappears 2 Answers