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 Roistock · Nov 01, 2016 at 10:06 AM · c#bugfloatprivate

Float sets itself to zero

I scrapped the excess out, but there is a really mind bogling problem in the code. Look at the void Start() I can't understand why private floats, that are set to 1.0f are zero?

using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UI; using System; using System.Collections;

public class Minigame : MonoBehaviour {

 public CutoffTimer cutoff;
 public SprintConnection conn;
 public SprintPlayerData playerData;
 public Text minigameTimer;
 public Text minigameScore;
 public string timerText;

 public bool timeOver;

 private int tournamentId;
 private int minigameId;

 private int currentScore;

 private float interval1Sec;

 private float offlineTimeLeft;
 private float offlineTimeMax;
 private bool offline;

 private float onlineTimeLeft = 15;
 private float onlineTimeMax = 15;
 private bool onlineTimerSet;

 private float scaleFactor = 0.5f;

 private float accelerometer;
 private float gyroscope;
 int maxCheckCounter = 0;
 int maxCheckInterval = 6;

 **[System.NonSerialized]
 private float aK, bK, xK = 1.0f;
 void Start()
 {
     Debug.Log(bK + "," + aK); //<---- This returns 0,0 - even when above bK & aK are set to 1.0f?
     Input.gyro.enabled = true;
 }**

 public void updateScore(int score)
 {
     if (!timeOver)
     {
         currentScore = score;
         minigameScore.text = currentScore.ToString();
     }
 }
 public float GetAccelerometer(string xyz)
 {
     float acc = 4.0f / accelerometer;

     xyz = xyz.ToLower();
     if (xyz != "x" && xyz != "y" && xyz != "z")
     {
         return 0;
         Debug.Log("NOLLA?");
     }
     else
     {
         if (Application.platform == RuntimePlatform.WSAPlayerARM || Application.platform == RuntimePlatform.WSAPlayerX64 || Application.platform == RuntimePlatform.WSAPlayerX86)
         {
             switch (xyz)
             {
                 case "x":
                     return Math.Min(6.0f, Math.Max(-6.0f, Input.acceleration.x * 1.72f));
                     break;
                 case "y":
                     return Math.Min(6.0f, Math.Max(-6.0f, Input.acceleration.y * 1.7f));
                     break;
                 case "z":
                     return Math.Min(6.0f, Math.Max(-6.0f, Input.acceleration.z * 1.6f));
                     break;
                 default:
                     Debug.Log("NOLLA?");
                     return 0.0f;
                     break;
             }
         }
         else
         {
             switch (xyz)
             {
                 case "x":
                     return aK * Math.Min(4.0f, Math.Max(-4.0f, Input.acceleration.x * xK * acc));
                     break;
                 case "y":
                     return aK *  Math.Min(4.0f, Math.Max(-4.0f, Input.acceleration.y * bK * acc));
                     break;
                 case "z":
                     return aK * Math.Min(4.0f, Math.Max(-4.0f, Input.acceleration.z * bK * acc));
                     break;
                 default:
                     Debug.Log("NOLLA?");
                     return 0.0f;
                     break;
             }
         }
     };
 }

 public float GetGyro(string xyz)
 {
     float acc = 18 / gyroscope;


     xyz = xyz.ToLower();
     if (xyz != "x" && xyz != "y" && xyz != "z")
     {
         return 0;
     }
     else
     {
         switch (xyz)
         {
             case "x":
                 return Math.Min(4 * xK, Math.Max(-4 * xK, Input.gyro.rotationRate.x * acc));
                 break;
             case "y":
                 return Math.Min(4 * xK, Math.Max(-4 * xK, Input.gyro.rotationRate.y * acc));
                 break;
             case "z":
                 return Math.Min(4 * xK, Math.Max(-4 * xK, Input.gyro.rotationRate.z * acc));
                 break;
             default:
                 return 0;
                 break;
         }
     };
 }

}

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

1 Reply

· Add your reply
  • Sort: 
avatar image
5

Answer by hexagonius · Nov 01, 2016 at 10:33 AM

only xK is set to 1. Such one-liners define multiple variables at once, but each needs it's initial value when differing from 0.
Unfortunately there's no such syntax initializing all at once

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 Owen-Reynolds · Nov 01, 2016 at 04:09 PM 2
Share

As a follow-up, it might help to get an Intro to C# program$$anonymous$$g book and skim over the first few chapters (that's straight program$$anonymous$$g, not even C#. I even have an example covering exactly this in $$anonymous$$e.) You'll probably find a bunch of other rules you didn't know, save you a lot of time.

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

6 People are following this question.

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

Related Questions

Why inpector keeps methods assigned when changed from public to private 2 Answers

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

How to fix wobbling float when away from spawn? 1 Answer

Float bug... no errors. 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