【ゲームエンジン】Unityなんでも質問スレpart9at GAMEDEV【ゲームエンジン】Unityなんでも質問スレpart9 - 暇つぶし2ch■コピペモード□スレを通常表示□オプションモード□このスレッドのURL■項目テキスト363:名前は開発中のものです。 23/01/18 00:56:38.90 IfGZ9cna.net int b = 0; for(int i = 0; i < 3; i++) { int a = Random.Range (1,11); b += a } 364:名前は開発中のものです。 23/01/18 01:17:56.54 gb9xw2nh.net 回答ありがとうございます。 >>357自分がやりたいのはこれです。 for文を使ってやってみたのですがaの値が同じになってしまいます。 using System.Collections; using System.Collections.Generic; using UnityEngine; public class practice : MonoBehaviour { // Start is called before the first frame update void Start() { int a = Random.Range(1, 11); int b = 0; for (int i = 0; i < 3; i ++) { b += a; } Debug.Log(a); Debug.Log(b); } } これだとコンソールに3,9や5,15, 10,30と表示されます。 b = a + a + aも駄目でした。 365:名前は開発中のものです。 23/01/18 07:04:29.42 uieJtW94.net int a = Random.Range(1, 11) がfor文の外にあるんじゃaの値が変わるわけないだろ 次ページ最新レス表示レスジャンプ類似スレ一覧スレッドの検索話題のニュースおまかせリストオプションしおりを挟むスレッドに書込スレッドの一覧暇つぶし2ch