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 Robgar2001 · Aug 10, 2017 at 05:54 PM · bugtransform.positionvector2floats

Why does the code stops?

First of all excuse me for my bare English. If i run the code with the commands (//) enabled it will not do the calculation (will not print "is voorbij") (i tested this by printing a text message after the calculation is done). With those lines of code as a command // it works fine. Can somebody explain this to me?

   public int count;
     public GameObject enemy;
     public Transform spawn;
     void Start () {
         count = (int)Time.realtimeSinceStartup;
         EnemySpawnController ESC = new EnemySpawnController();
         ESC.CheckIfFree();
     }
     public void GoTOLocation(string name) {
         print ("Searching for gameobject with name:" + name);
         spawn.Find ("1");
 
         print ("x." + spawn.transform.position.x + "/" + spawn.transform.position.y);
 
 
         Vector2 diff;
         //diff.x = spawn.transform.position.x-gameObject.transform.position.x;
         //diff.y = spawn.transform.position.y-gameObject.transform.position.y;
 
         print ("is voorbij");
 
         if (x != enemy.transform.position.x) { gameObject.transform.Translate(Vector2.right * diff.x); }
         if (y != enemy.transform.position.y) { gameObject.transform.Translate(Vector2.up * diff.y); }
     }
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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by TheSOULDev · Aug 10, 2017 at 06:17 PM

// is commenting, meaning that anything after // in a line won't be compiled.

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

Answer by arain55 · Aug 10, 2017 at 06:22 PM

Hi @Robgar2001 , those are comments and they are not executed by the compiler and are only there for the people writing the code or reading the code to inform them what that line of code does. eg:

 //this line prints Hello world to the unity console
 print("Hello world") 
 the line above will print Hello world to the unity console and the comment above describes what it does.
 
 //print("Hello world")
 that will print nothing as it is ignored by the compiler, in other words it is not executed.

there are two types of comments multiline and one line

look here for more info: http://www.c-sharpcorner.com/uploadfile/puranindia/comments-in-C-Sharp/

and please before you start using unity learn a programming language, such as C# and that will avoid questions such as this which are unnecessary

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

Answer by Robgar2001 · Aug 10, 2017 at 07:52 PM

@arain55 @TheSOULDev I know i know but i mean when i remove the // the code won't print the "is voorbij" message. So those two lines avoid the computer to print the "is voorbij" message. And i want to know why those lines avoid that. (I know how the command system works)

Comment
Add comment · Show 2 · 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
avatar image arain55 · Aug 10, 2017 at 11:48 PM 0
Share

Oh right , sorry. Um it's probably because theres an error, are you getting an error? if so what is it and change line 16

 Vector2 diff;
 
 to :
 
 Vector2 diff = new Vector 2 ((spawn.transform.position.x-gameObject.transform.position.x),(spawn.transform.position.y-gameObject.transform.position.y))

and remove the two lines underneath it and see if it solves anything

avatar image Robgar2001 arain55 · Aug 11, 2017 at 03:06 PM 0
Share

I changed it still nothing, also no error. I do see that the cords of the spawn transform are not correct. I changed it to an GameObject but still nothing. $$anonymous$$aybe theire is something worng with the loading of the spawn GameObject, that could explain why he doesn't want to do the calculation at the vector2.

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

74 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

Related Questions

Collision issues with Vector2.Reflect 1 Answer

How to find total distance from start to end of an array which stores positions in vector3? 2 Answers

Rigidbody2D.Velocity = Vector2 not changing X Position 1 Answer

Not able to fire projectiles at mouse position 2 Answers

moving objects with transform position 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