Unity绘制抛物线<25/11/2017>
获取GetMouseButtonDown初始点和GetMouseButton实时点的向量长度,替换里面的抛物线最高高度,进行微调可以弄出自己想要的效果
实际运用效果如下:
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53using UnityEngine; using System.Collections; using System.Collections.Generic; [ExecuteInEditMode] public class Parabola : MonoBehaviour { //重力 [Range(0,1)] public float gravity = 0.13f; //最大长度 public float maxLength = 50; //两点之间的距离 const float length = 0.2f; //点集合 List<Vector3> m_List = new List<Vector3>(); Material m_LineMat; public void OnRenderObject() { CreateLineMaterial(); m_LineMat.SetPass(0); Vector3 position = transform.position; Vector3 forward = transform.rotation * Vector3.forward * length; Vector3 newPos = position; Vector3 lastPos = newPos; m_List.Add(newPos); int i = 0, iMax = 0; float dis = 0; while (dis < maxLength) { i++; newPos = lastPos + forward + Vector3.up * i * -gravity * 0.1f; dis += Vector3.Distance(lastPos, newPos); m_List.Add(newPos); lastPos = newPos; } GL.Begin(GL.LINES); i = 0; iMax = m_List.Count; for (i = 0; i < iMax; i++) { GL.Vertex(m_List[i]); } GL.End(); m_List.Clear(); } void CreateLineMaterial() { if (!m_LineMat) { var shader = Shader.Find("Hidden/Internal-Colored"); m_LineMat = new Material(shader); m_LineMat.hideFlags = HideFlags.HideAndDontSave; m_LineMat.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha); m_LineMat.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha); m_LineMat.SetInt("_Cull", (int)UnityEngine.Rendering.CullMode.Off); m_LineMat.SetInt("_ZWrite", 0); } } }
最后
以上就是朴素羊最近收集整理的关于Unity绘制抛物线的全部内容,更多相关Unity绘制抛物线内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复