知りたいこと
変更自体は別の方法でできるようになったのですが、理由を知りたかったので質問させていただきます。
ボタンコンポーネントを押した際に、画像を指定の座標位置に移動させる命令を考えていたのですが、
case "01"、"04"の命令文では何回押しても問題なく座標変更してくれるのですが、
case "02"、"03"の命令文だと、一回目は座標変更するが、二回目以降は反応しません。
02を押す(一回目)移動する→03を押す(一回目)移動する→02を押す(二回目以降)移動しない→03を押す(二回目以降)移動しない
という感じです。
(もともと02の命令で実行していたが、そもそもこんな過程を踏む必要がないと気づき01の命令に変更した)
C#:
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4using UnityEngine.UI; 5 6public class PointBulb : MonoBehaviour 7{ 8 GameObject P ; 9 GameObject casole; 10 RectTransform cp; 11 12 Vector3 pos; 13 Vector3 newpos; 14 Vector3[] yubipos = new Vector3[] //指のアイコンをこれらの座標に移動させる 15 { 16 new Vector3 (158,97,0),new Vector3 (44,88,0),new Vector3 (-322,-131,0),new Vector3 (109,-84,0) 17 }; 18 void Start() 19 { 20 casole = GameObject.FindWithTag("casole"); 21 cp = casole.GetComponent<RectTransform>(); 22 P = transform.parent.gameObject; 23 24 } 25 26 // Update is called once per frame 27 void Update() 28 { 29 if( pos != newpos ) 30 { 31 pos = newpos; 32 Debug.Log("pos" + pos); 33 Debug.Log("newpos" + newpos); 34 35 cp.localPosition = newpos; 36 } 37 } 38 39 public void Change() 40 { 41 switch (P.name) 42 { 43 case "01" : 44 cp.localPosition = yubipos[00]; 45 break; 46 47 case "02" : 48 newpos = yubipos[01]; 49 break; 50 51 case "03" : 52 newpos = yubipos[02]; 53 break; 54 55 case "04" : 56 cp.localPosition = yubipos[03]; 57 break; 58 } 59 } 60} 61
命令的には紆余曲折を経ていますが、やっていることは01も02も同じはずなのに、なぜ02は一度しか命令が実行されないのでしょうか?
お分かりになる方がいらっしゃれば、回答お待ちしています。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/08/01 08:47