Unity初学者から,物理判定について質問です.
添付写真のように,楕円を上から下に落として積み上げるプログラムをUnityで作成しています.
積み上げが進むと楕円の数が多いためか処理が重い・物理演算に時間が掛かってしまいます.
そのため積み上げの途中で下に溜まっている楕円は随時物理演算を停止し,処理を軽くしたいのですが,どのように行うのが適切でしょうか?
以下が現状、各楕円にアタッチしているスクリプトです
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class Ellipse : MonoBehaviour 6{ 7private bool make_next = true; 8private float x; 9private float maked_time = 0.0f; 10Rigidbody rb; 11private bool stoped = true; 12 13void Start() 14{ 15x = transform.position.x; 16} 17// Update is called once per frame 18void Update() 19{ 20if (Time.time - maked_time > 0.3f && make_next) 21{ 22make_next = false; 23// 次の楕円を生成する処理 24FindObjectOfType<DropDownEllipseMiddle>().NewEllipse(x); 25} 26else if(Time.time - maked_time > 10.0f && stoped) 27{ 28Stop(); 29} 30} 31 32void Stop() 33{ 34stoped = false; 35rb = this.gameObject.GetComponent<Rigidbody>(); 36rb.isKinematic = true; 37} 38}
このスクリプトだと
There is no 'Rigidbody' attached to the "" game object, but a script is trying to access it. You probably need to add a Rigidbody to the game object "". Or your script need to check if the component is attached before using it.
と警告が表示されます(プログラムが止まるわけではありません)
物理演算は停止しても,当たり判定は働いたままにしたいです.
またプログラムそのものの処理が軽くなれば良いため,下にある楕円の物理演算を停止させるのはあくまで手段の一つです.処理を軽くする良いアイデアはありますでしょうか?
もしあればご教授いただけると幸いです.
