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 /
avatar image
0
Question by SebGM2019 · Sep 22, 2018 at 03:35 AM · scripting problemgamedesign

if position not working

Hi, I have a problem with checking if my gameobject is on a position, let me explain: I'm making a game with a kind of "Slider", like the Unity UI Slider, (But not using the slider, it's just to compare), this Slider was made with GameObjects. The cursor was designed to move automatically and you press the screen when the cursor is in a specific zone. This is the cursor code:

 private System.Random FirstRnd = new System.Random();
     private int FirstCounter;
     private float Speed = 50f;
     private float AntiSpeed = -50f;
     private int SecondCounter;
     private System.Random SecondRnd = new System.Random();
     private Vector3 StartLVector = new Vector3(-2.05f, -0.55f, 10f);
     private Vector3 StartRVector = new Vector2(2.05f, -0.55f);
     private Vector3 CenterL = new Vector3(-0.02f, 0.55f, 10f);
     private Vector3 CenterR = new Vector3(1.14f, -0.55f, 10f);
     private GameObject Cursor;
 
     // Use this for initialization
     void Start ()
     {
         Cursor = GameObject.Find("Cursor");
     }
     private void FixedUpdate()
     {
         SecondStarting();
     }
     void Starting()
     {
         FirstCounter = FirstRnd.Next(1, 3);
         if (FirstCounter == 1)
         {
             transform.position = StartLVector;
         }
         else if (FirstCounter == 2)
         {
             transform.position = StartRVector;
         }
     }
     void SecondStarting()
     {
         Debug.Log("Puga");
         if (Cursor.transform.position == StartLVector)
         {
             Cursor.transform.Translate(Speed, 0, 0);
         }
         else if (Cursor.transform.position == StartRVector)
         {
             Cursor.transform.Translate(AntiSpeed, 0, 0);
         }
         else if (Cursor.transform.position == CenterL)
         {
             SecondCounter = SecondRnd.Next(1, 3);
             if (SecondCounter == 1)
             {
                 Cursor.transform.Translate(Speed, 0, 0);
             }
             else if (SecondCounter == 2)
             {
                 Cursor.transform.Translate(AntiSpeed, 0, 0);
             }
         }
         else if (Cursor.transform.position == CenterR)
         {
             SecondCounter = SecondRnd.Next(1, 3);
             if (SecondCounter == 1)
             {
                 Cursor.transform.Translate(Speed, 0, 0);
             }
             else if (SecondCounter == 2)
             {
                 Cursor.transform.Translate(AntiSpeed, 0, 0);
             }
         }
     }
 }


As far I can see, I don't detect a problem here. Do you see something?

Comment
Add comment · Show 2
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
avatar image SebGM2019 · Sep 22, 2018 at 03:38 AM 0
Share

I want to add something, the message "Puga" yes prints, but, below it, nothing seems to compile

avatar image Seth-Bergman · Sep 22, 2018 at 08:02 AM 0
Share

Have you added debug logs to each of your loops to see what’s getting called when? Good place to start.. does it move at all? What happens? Offhand, you tell the object to translate if it has a certain position, that will only happen for one frame before it is no longer true.. also, you repeat a block of code, that should be a separate method you call twice for more manageable code.. overall, I still can’t quite put together how this is meant to work though..

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by LCStark · Sep 22, 2018 at 07:58 AM

You are comparing Cursor.transform.position to some values and none of them match. Try displaying the Cursor.transform.position in the Debug.Log and see what value it really has. You probably will want to use transform.localPosition instead.

Comment
Add comment · Share
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

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

162 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Character Controller squeezed between colliders freezes Unity 0 Answers

Have an object only visible when input is held down 1 Answer

Unity 8.1 How to get text via script 0 Answers

Is there a reason why Unity would be able to read one variable in a script and not another? 1 Answer

Why isn't my instance of an object moving? 1 Answer


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