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 /
This question was closed Feb 15, 2018 at 07:03 AM by Koblih161 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Koblih161 · Feb 10, 2018 at 07:33 PM · vector3accelerometer

What did i do wrong? ":" is wrong expression?,What did I do wrong? ":" is wrong expression

 void FixedUpdate () {
     var speed = 10.0;
     var dir :  Vector3 = Vector3.zero;

     dir.x =-Input.acceleration.y;
     dir.z = Input.acceleration.x;

         if (dir.sqrMagnitude > 1)
             dir.Normalize();

         dir*= Time.deltaTime;

     transform.Translate(dir * speed);

 }
Comment
Add comment · Show 1
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 SonicScrew12 · Feb 10, 2018 at 07:55 PM 0
Share

Are you using C# or JavaScript? JavaScript syntax for declaring variables is different than C#'s.

2 Replies

  • Sort: 
avatar image
1
Best Answer

Answer by Meguia · Feb 10, 2018 at 07:58 PM

Tip: Use variable types.
Tip: Don't multiply Vector3 * Double.
Pro tip: use {} even if it's a line ;-)

Try this:

 void FixedUpdate () {
     float speed = 10.0F;
     Vector3 dir = Vector3.zero;
 
     dir.x =-Input.acceleration.y;
     dir.z = Input.acceleration.x;
     if (dir.sqrMagnitude > 1){
              dir.Normalize();
     }
     dir*= Time.deltaTime;
     transform.Translate(dir * speed);
 }
Comment
Add comment · Show 1 · 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 Koblih161 · Feb 15, 2018 at 07:03 AM 0
Share

I understand now Thanks ;-)

avatar image
0

Answer by Pigenator · Feb 10, 2018 at 07:47 PM

Well i'd imagine your use of : in "var dir : Vector3 = Vector3.zero" is wrong, but I don't use unityscript so i don't know how it's supposed to be.

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 fafase · Feb 10, 2018 at 08:13 PM 0
Share

It's C#. var is used in C#.

avatar image SonicScrew12 fafase · Feb 10, 2018 at 08:17 PM 0
Share

Not necessarily. Unity prefers explicit types like int, float, bool, etc. Var doesn't really have a place in UnityScript, as far as I'm concerned. It's more used in JavaScript.

Follow this Question

Answers Answers and Comments

94 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

Related Questions

How to Use Accelerometer to Move Object by Tilting Phone? 1 Answer

Acceleration and accelerometer calibration 0 Answers

Having some problem with AI finding a vector3... 0 Answers

Rotation Perpendicular to Line Segment 1 Answer

How to compare limits for creating new objects in world space? 0 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