前提・実現したいこと
オブジェクトを一定時間ごとに回転させるプロジェクトを作成しており、そのためvoid update ではなく fixed update を使用しています
Zed MiniでそのオブジェクトをAR表示させようとしているのですが、Unityの再生ボタン(▶)を押した後にAR表示をするための処理が始まり、プロジェクト自体は動いているのですが、数秒立ったのちにAR表示がされるため、その数秒間は回転が描画されません(1秒ごとに10度ずつ回転する場合に初期角度が0度だとした場合に、AR表示が4秒後に始まるため、40度から描画が始まります)
そのため、void start時に10秒待った後、FixedUpdateを実行したいです
Invoke("FixeUpdate", 10.0f);をvoid startに書いたのですが、10秒待たずにすぐFixedUpdateが読み込まれ始めてしまいました
解決方法をご存じの方はお力をお貸ししていただけると幸いです
発生している問題・エラーメッセージ
10秒待った後にFixeUpdateを同じ周期で実行させるためにInvoke("FixeUpdate", 10.0f);をvoid startに書いたのですが、10秒待たずにすぐFixedUpdateが読み込まれ始めてしまいました
該当のソースコード
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class TestMoving : MonoBehaviour 6{ 7 private float timeleft = 0.00001f; 8 private float timeOut; 9 private float timeElapsed = 0; 10 int C; 11 int B; 12 //double[] kakudo = {0,-42.0508,72.00072,-78.18052,80.8984,-22.26026,82.40628,-112.76628,101.30362,13.05942,128.13218,-152.81002,81.25238,-120.49422,90.03896,-126.09498,59.83032,-49.36734,-4.8268,-75.042,45.63372,4.75948,95.0048,-116.85234,62.36758,-85.81166,-24.2165,-136.87806,108.09436,-104.17704,31.06268,-18.56162,85.29334,-94.63366,114.08056,-54.7327,67.82864,-150.97742,27.08288,-122.36862,53.39862,-153.18842,83.49176,-35.71788,87.98724,-53.88196,21.67946,-34.48478,79.1296,-109.37784,37.25854,-88.14234,43.8559,-135.6014,79.93634,-102.99366,102.56334,-59.12104,66.5192,-129.98766,-78.13916,-210.81962,58.73164,-58.26172,146.63528,-118.47726,126.90018,-140.3127,79.27656,-108.39356,105.8519,-132.9636,100.71204,29.99612,123.30516,-139.79196,91.5233,7.51366,42.7075,-156.2891,7.2006,-92.91832,17.87302,-73.31346,24.23058,-85.36506,-64.74886,-156.4552,100.07822,20.559,85.21854,-135.07956,84.40498,-95.22194,0}; 13 //int[] changepoint = {0, 828, 1463, 2037, 2605, 3140, 3644, 4259, 4880, 5459, 6053, 6953, 7917, 8957, 10168, 11207, 12301, 13123, 13595, 14110, 14706, 15135, 15631, 16283, 17229, 17796, 18310, 18861, 19491, 20085, 20585, 20970, 21472, 22086, 23172, 24150, 25093, 26303, 26909, 27405, 27951, 28514, 29116, 29633, 30396, 30937, 31686, 32174, 32660, 33217, 33760, 34246, 34802, 35354, 36227, 36809, 37577, 38113, 38584, 39153, 39550, 40057, 40697, 41322, 42198, 43032, 43776, 44631, 45600, 46506, 47315, 48115, 48894, 49390, 49863, 50552, 51181, 51703, 52064, 52746, 53318, 53786, 54286, 54729, 55206, 55704, 56017, 56495, 57136, 57607, 58005, 58700, 59333, 59954, 60345}; 14 double[] kakudo = {0,-3.9,-16.6,-7.7,11,-1.5,-22,1.6,-8.5,2.4,15.4,-9.8,18.2,-21.6,-12,-3.7,-20.1,-1.5,6.3,-20.3,17.2,-8.5,5.4,22.1,1.4,-15.3,-1.8,-11.6,0.6,18.1,10.8,-5.2,-22,5.8,-13.9,22.3,-2.5,16.3,3.1,1.1,-10.1,15.5,-16.5,16.4,-4.8,12.4,-0.4,5.5,-18.1,-3.2,6.9,-6.2,11.4,-8.1,-21.9,4.2,12.1,-5.1,8.7,-10.2,18.4,-3.3,-12.7,-20.5,11.4,-3.7,-20.9,4.2,-19.1,4.1,-9.1,8.8,15.4,-18.4,16.6,6.9,16.6,0.3,-19.6,17.4,4.2,-5.5,-20.5,21.4,-5.3,12.3,-3.3,5.5,15.1,-3.3,4.5,16.3,4.2,-8.2,5.6,-12.4,5,-21.1,7.9,-6.8,15.4,-3.1,16.8,1.2,-8.1,7.2,20.5,11.5,-5.4,-20.5,12.2,-13.8,1.1,18.8,-3.6,12.2,-11.4,-3.3,-16.2,4.5,-19.1,1.2,8.6,-6.1,8.8,-15.6,-1.7,-11.7,4.1,-11.7,-0.8,9.9,19.1,-1.1,-14.4,7.2,20.6,5.3,-8.2,12.4,19.2,10.6,-4.5,-11.2,2.7,19.8,-6.4,18.4,7.4,-0.7,9.8,-12.2,0.9,-10.8,9.4,19,-18.8,-12.7,-21.5,19.3,0.8,-13,11.7,0.7,9.4,-8.2,6.8,-11.1,-18.9}; 15 int[] changepoint = { 0,176,496,764,1150,1464,1872,2310,2600,2902,3218,3662,4130,4690,4958,5226,5596,5990,6226,6680,7222,7670,7998,8368,8780,9138,9458,9728,10030,10414,10672,11018,11396,11876,12282,12826,13278,13674,14008,14112,14420,14878,15388,15904,16318,16690,17010,17226,17660,18006,18288,18610,18984,19378,19712,20170,20422,20794,21128,21518,21996,22412,22686,22936,23440,23784,24158,24608,25042,25476,25806,26188,26414,26932,27458,27730,28002,28358,28762,29310,29642,29910,30266,30852,31324,31712,32080,32366,32620,32986,33206,33536,33870,34160,34468,34826,35176,35614,36078,36396,36798,37162,37542,37874,38172,38542,38844,39082,39470,39794,40290,40730,41054,41450,41892,42270,42724,43012,43360,43788,44242,44666,44870,45186,45504,45924,46228,46476,46804,47132,47394,47716,47952,48330,48684,49122,49418,49738,50096,50526,50710,50930,51306,51486,51786,52184,52666,53136,53468,53674,53922,54314,54602,54870,55244,55558,56128,56396,56702,57294,57710,58000,58414,58664,58874,59214,59522,59866,60160}; 16 int i = 0; 17 double ave; 18 int jp = 0; 19 float bunbo; 20 float bunsi; 21 float totaltime; 22 int mai = 1; 23 float X; 24 float Y; 25 float ZZ = 0; 26 int CHcount = 0; 27 28 // Start is called before the first frame update 29 void Start() 30 { 31 X =Mathf.Sin( (float)(kakudo[jp+1])* Mathf.Deg2Rad);//停止位置だす 32 Y =Mathf.Cos((float)(kakudo[jp+1]) * Mathf.Deg2Rad); 33 Debug.Log("X Is" + X); 34 Debug.Log("Y" + Y); 35 Vector3 pos = this.gameObject.transform.position; 36 this.gameObject.transform.position = new Vector3 (1 *X,0,(1*Y)); //矢印を停止位置に 37 38 if (kakudo[jp +1] > kakudo[jp + 0])//正方向の回転の場合 39 { 40 transform.rotation = Quaternion.Euler(0.0f, ((float)kakudo[jp + 1] - 90), 180f); 41 Debug.Log("kaitenn1"); 42 CHcount = CHcount + 1; 43 } 44 else if (kakudo[jp +1] <= kakudo[jp]) //負の場合 45 { 46 // transform.Rotate(new Vector3(0, ((float)kakudo[jp + 1]) + 90, 0)); 47 transform.rotation = Quaternion.Euler(0.0f, ((float)kakudo[jp + 1] + 90), 0.0f); 48 Debug.Log("kaitenn2"); 49 CHcount = CHcount + 1; 50 } 51 Invoke("FixeUpdate", 30.5f); 52 } 53 54 // Update is called once per frame 55 void FixedUpdate() 56 { 57 //Debug.Log("UP Start"); 58 totaltime = totaltime + Time.deltaTime; 59 i = (int)(totaltime * 1000.0f); 60 61 bunbo = changepoint[jp + 1] - changepoint[jp]; 62 bunsi = changepoint[jp+1] - i + 0.001f; 63 // UnityEngine.Debug.Log("経過時間は ==" + i); 64 if (changepoint[jp+1]==i || Mathf.Abs(changepoint[jp+1] - i) < 15 ) 65 { 66 //UnityEngine.Debug.Log("始まりました"); 67 ZZ = 180f; 68 69 X =Mathf.Sin( (float)(kakudo[jp+2])* Mathf.Deg2Rad); 70 Y =Mathf.Cos((float)(kakudo[jp+2]) * Mathf.Deg2Rad); 71 72 Vector3 pos = this.gameObject.transform.position; 73 this.gameObject.transform.position = new Vector3 (1 *X,0,(1*Y)); 74 75 if (kakudo[jp +2] > kakudo[jp + 1]) 76 { 77 transform.rotation = Quaternion.Euler(0.0f, ((float)kakudo[jp + 2] - 90), ZZ); 78 Debug.Log("- → +"); 79 UnityEngine.Debug.Log("停止角度は = " + kakudo[jp + 2]); 80 CHcount = CHcount + 1; 81 jp = jp + 1; 82 UnityEngine.Debug.Log("回転数は = " + CHcount); 83 } 84 else if (kakudo[jp +2] <= kakudo[jp + 1]) 85 { 86 transform.rotation = Quaternion.Euler(0.0f, ((float)kakudo[jp + 2] + 90), 0.0f); 87 Debug.Log("+ → -"); 88 UnityEngine.Debug.Log("停止角度は = " + kakudo[jp + 2]); 89 CHcount = CHcount + 1; 90 jp++; 91 UnityEngine.Debug.Log("回転数は = " + CHcount); 92 } 93 94 } 95 } 96} 97
試したこと
10秒待った後にFixeUpdateを同じ周期で実行させるためにInvoke("FixeUpdate", 10.0f);をvoid startに書いたのですが、10秒待たずにすぐFixedUpdateが読み込まれ始めてしまいました
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
回答4件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/05/28 09:55
2020/05/28 09:58