LineRenderer初探
如圖給角色繪製遊戲中可見的視野範圍:
using UnityEngine;
using System.Collections;
public class LineRenderSee : MonoBehaviour {
public float fieldOfViewAngle = 90;
public float viewDistance = 10;
public Color theColor = Color.yellow;
public float lineWidth = 0.1f;
private LineRenderer lineRenderer;
// Use this for initialization
void Start () {
lineRenderer = gameObject.AddComponent<LineRenderer>();
//設定材質
lineRenderer.material = new Material(Shader.Find("Particles/Additive"));
//設定點的最大值, 如果大於實際使用的點, 會把剩餘的點設定成Vector3.zero
lineRenderer.SetVertexCount (11);
//設定顏色
lineRenderer.SetColors(theColor, theColor);
//設定寬度
lineRenderer.SetWidth(lineWidth, lineWidth);
}
// Update is called once per frame
void Update () {
Quaternion r1 = Quaternion.Euler (transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y - fieldOfViewAngle / 2f, transform.rotation.eulerAngles.z);
Quaternion r2 = Quaternion.Euler (transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y - fieldOfViewAngle / 3.5f, transform.rotation.eulerAngles.z);
Quaternion r3 = Quaternion.Euler (transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y - fieldOfViewAngle / 6f, transform.rotation.eulerAngles.z);
Quaternion r4 = Quaternion.Euler (transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y - fieldOfViewAngle / 8f, transform.rotation.eulerAngles.z);
Quaternion r5 = transform.rotation;
Quaternion r6 = Quaternion.Euler (transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y + fieldOfViewAngle / 8f, transform.rotation.eulerAngles.z);
Quaternion r7 = Quaternion.Euler (transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y + fieldOfViewAngle / 6f, transform.rotation.eulerAngles.z);
Quaternion r8 = Quaternion.Euler (transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y + fieldOfViewAngle / 3.5f, transform.rotation.eulerAngles.z);
Quaternion r9 = Quaternion.Euler (transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y + fieldOfViewAngle / 2f, transform.rotation.eulerAngles.z);
Vector3 f1 = transform.position + r1 * Vector3.forward * viewDistance;
Vector3 f2 = transform.position + r2 * Vector3.forward * viewDistance;
Vector3 f3 = transform.position + r3 * Vector3.forward * viewDistance;
Vector3 f4 = transform.position + r4 * Vector3.forward * viewDistance;
Vector3 f5 = transform.position + r5 * Vector3.forward * viewDistance;
Vector3 f6 = transform.position + r6 * Vector3.forward * viewDistance;
Vector3 f7 = transform.position + r7 * Vector3.forward * viewDistance;
Vector3 f8 = transform.position + r8 * Vector3.forward * viewDistance;
Vector3 f9 = transform.position + r9 * Vector3.forward * viewDistance;
lineRenderer.SetPosition (0, transform.position);
lineRenderer.SetPosition (1, f1);
lineRenderer.SetPosition (2, f2);
lineRenderer.SetPosition (3, f3);
lineRenderer.SetPosition (4, f4);
lineRenderer.SetPosition (5, f5);
lineRenderer.SetPosition (6, f6);
lineRenderer.SetPosition (7, f7);
lineRenderer.SetPosition (8, f8);
lineRenderer.SetPosition (9, f9);
lineRenderer.SetPosition (10, transform.position);
}
}
相關文章
- Deno 初探
- ELK初探
- Nginx 初探Nginx
- Mobx 初探
- jQuery初探jQuery
- 初探IndexedDBIndex
- 初探PWA
- Puppeteer 初探
- Redis初探Redis
- 初探Firewalld
- Serverless初探Server
- Promise初探Promise
- Quantum 初探
- 初探TCPTCP
- ## RATreeView 初探View
- puppeteer初探
- Quartz初探quartz
- MapDB初探
- Vue初探Vue
- Docker初探Docker
- angr初探
- Gitee初探Gitee
- 初探canvasCanvas
- pointerEvent 初探
- websoctet初探Web
- RxJava 初探RxJava
- GoLang初探Golang
- Django初探Django
- orm初探ORM
- 初探 TypeScriptTypeScript
- ECharts 初探Echarts
- 初探websocketWeb
- zookeeper初探
- ARKit 初探
- 初探Lucene
- ElasticSearch初探Elasticsearch
- MongoDB初探MongoDB
- MapReduce初探