Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by lascott21 · Oct 11, 2018 at 09:25 AM · cursoraimingcrosshair

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

153 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges