jojoburaki
@jojoburaki

Are you sure you want to delete the question?

Leaving a resolved question undeleted may help others!

unity オブジェクトの座標指定を教えてください

Q&A

Closed

このプログラムで生成したオブジェクトの座標を変える方法とオブジェクトが2個以上生成されたときに重ならないようにする方法を教えてください。お願いします。

{
   private Animator animator;
    private int number,i,z,count,countdown;
private string currentStateName;
private float _repeatSpan;    //繰り返す間隔
private float _horyuuSpan;   
private float _timeElapsed2;
private float _timeElapsed;   //経過時間
private GameObject kaitenText; // 回転数を表記
[SerializeField]private GameObject insObj;//生成するオブジェクト(Unityのインスペクターでアタッチしてください)
private List<GameObject> insObjList = new  List<GameObject>();//生成したオブジェクトのリスト


    private void Start()
    {
         count=0;//保留数
         countdown=0;
        _repeatSpan = 9; 
        _horyuuSpan = 3;
        
        _timeElapsed = 0;   //経過時間をリセット
        _timeElapsed2=0;

    }


void Update()
    {



    number = Random.Range (1, 9);
    animator = GetComponent<Animator>();
     animator.SetInteger("taiki",i);
     animator.SetInteger("wait",z);
     
    
     


        if(Input.GetKeyDown(KeyCode.LeftArrow))//カウンター
        {
        if(_timeElapsed<=3){
        i=1;
        }
        animator.SetInteger("zugara",number);
        if(count<=4){
        count+=1;
        countdown=1;
        z=1;
       Debug.Log("カウント+1");
       Debug.Log(count);

         //ここでオブジェクト生成
                //消すためにListに保持
                insObjList.Add(Instantiate(insObj));


       }
        }

        if(i==1){
       _timeElapsed2 +=Time.deltaTime;
        }

       if (_timeElapsed2 >= _horyuuSpan)
        {
        i=0;
        Debug.Log("待機");
         _timeElapsed2= 0;   //経過時間をリセットする
        }
       

       //時間をカウントする
       if(countdown==1){
        _timeElapsed += Time.deltaTime; 
        }


        //経過時間が繰り返す間隔を経過したら
        if (_timeElapsed >= _repeatSpan)
        {
        count--;
        Debug.Log("カウント-1");
        Debug.Log(count);
        if(0<count&&count<=4)
        {
        i=1;
        Debug.Log("待機解除");
        animator.SetInteger("zugara",number);
        }
           countdown=0;
           
            _timeElapsed = 0; 
            _timeElapsed2= 0;//経過時間をリセットする

        if(0<count&&count<=4)
        {
        countdown=1;
        }
          if(insObjList.Count != 0)
            {

                int index = 0;//任意の配列番号
                Destroy(insObjList[index]);//オブジェクト消す
                insObjList.RemoveAt(0);//箱から消す
        }

        }
        }
}
0

No Answers yet.

Your answer might help someone💌