###前提、実現したいこと
前提・実現したいこと
曲線のレール上(位置は固定)に球体を転がそうと考えています。初速度は0で、球体の初期位置をインスペクターからパラメタθの値を弄って設定できるようにしたいです。(0°<=θ<=60°)
発生している問題・エラーメッセージ
C#スクリプトを作成、保存してもエラーメッセージは表示されませんでしたが、球体オブジェクトにアタッチしてシーンを再生しても球体は指定した位置へ移動しませんでした。
該当のソースコード
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class initializeA : MonoBehaviour 6{ 7 8 public float theta; 9 private float costheta; 10 private float sintheta; 11 12 void Start() 13 { 14 costheta = Mathf.Cos(theta * (Mathf.PI / 180)); 15 sintheta = Mathf.Sin(theta * (Mathf.PI / 180)); 16 17 Transform mytrans = this.transform; 18 Vector3 pos = mytrans.position; 19 pos.x = 0.0f; 20 pos.y = 1.0f - 0.9f * costheta; 21 pos.z = -1 * 0.9f * sintheta; 22 } 23}
試したこと
thetaを一先ずおいて、pos.x, pos.y, pos.z に定数値(2.0f)を代入した場合も、同様に初期位置は変化しませんでした。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/06/20 09:48