前提・実現したいこと
最近Unityをはじめました。
このプログラムをわかりやすく説明してほしいです。
できれば一行ずつお願いします。
(投射の落下地点を調べるスクリプトらしいです。)
発生している問題
DrawParabolicLine.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DrawParabolicLine : MonoBehaviour {
public Vector3 dir = new Vector3(10f, 10f, 10f);
public Vector3 origin = Vector3.zero;
public float calcTime = 5f;
[SerializeField, Range(0.001f,0.5f)]public float timeScale = 0.1f;
// Use this for initialization
void Start () {
} // Update is called once per frame void Update () { Vector3 pos = origin; Vector3 newPos = pos; float time = 0f; List<Vector3> posList = new List<Vector3>(); while(time<calcTime){ Vector3 dirXZ = new Vector3(dir.x, 0f, dir.z); // h=v0t+1/2*g*t^2 float h = dir.y*time + 0.5f * Physics.gravity.y * time * time; newPos = origin + dirXZ * time + Vector3.up * h; posList.Add(newPos); Debug.DrawLine(pos, newPos, Color.yellow); pos = newPos; time += timeScale; } }
}