配列の数値を動かしたいです。
こんな感じのブロックを積み上げるゲームを制作中です。
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class DestroyRed: MonoBehaviour 6{ 7 public GameManagerScripts scripts; 8 void Start() 9 { 10 } 11 12 public void OnTriggerEnter2D(Collider2D other) 13 { 14 if (other.gameObject.tag == "Red") 15 { 16 scripts.destroyblockLeft = true; 17 Destroy(this.gameObject); 18 } 19 else if (other.gameObject.tag == "RedRight") 20 { 21 scripts.destroyblockRight = true; 22 Destroy(this.gameObject); 23 } 24 25 } 26 27} 28 29 30 31 32
c#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4using UnityEngine.UI; 5using System; 6 7public class GameManagerScripts : MonoBehaviour 8{ 9 10 11 12 public List<Transform> testListA = new List<Transform>(); 13 public int l; 14 15 16 // Start is called before the first frame update 17 void Start() 18 { 19 destroyblockLeft = false; 20 destroyblockRight = false; 21 l = 0; 22 } 23 24 25 26 public void ControlButtonASD1() 27 { 28 29 30 if (Input.GetKeyUp(KeyCode.A)) 31 { 32 33 ListA[k].transform.position = testListA[l].transform.position; 34 k++; 35 l++; 36 if (destroyblockLeft == true) 37 { 38 l--; 39 } 40 doeshaveblockC = false; 41 control1 = true; 42 control3 = false; 43 } 44 45 if (Input.GetKeyUp(KeyCode.S)) 46 { 47 ListC[k].transform.position = testListS[y].transform.position; 48 k++; 49 y++; 50 doeshaveblockC = false; 51 control1 = true; 52 control3 = false; 53 } 54 55 if (Input.GetKeyUp(KeyCode.D)) 56 { 57 if(destroyblockRight == true) 58 { 59 r--; 60 } 61 62 ListC[k].transform.position = testListD[r].transform.position; 63 r++; 64 k++; 65 doeshaveblockC = false; 66 control1 = true; 67 control3 = false; 68 } 69 70 71 } 72 73 74 75 76 77 78 79}
GameManagerScriptsとDestroyRedの二つのスクリプトがありまして、
tag"Red"に当たると変数l、変数rが減るようにしたいのですが、うまく作動しません。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/03/18 07:43
2019/03/18 07:43
2019/03/18 07:53
2019/03/18 12:14
2019/03/18 12:36
2019/03/18 12:51