Синтаксис:
Используется csharp
using UnityEngine;
using System.Collections;
public class lightining : MonoBehaviour {
private LineRenderer linerender;
public Color color=Color.black;
public float StartWidth=0.1f;
public float EndWidth=0.1f;
private Vector3 curPos;
private Vector3 newPos;
private Vector3 oldPos;
private int number_of_points=500;
// Use this for initialization
void Start () {
linerender = GetComponent("LineRenderer") as LineRenderer;
linerender.SetColors(color,color);
linerender.SetWidth(StartWidth,EndWidth);
linerender.SetVertexCount(number_of_points);
linerender.SetPosition(0,transform.position);
curPos=transform.position;
}
// Update is called once per frame
void Update () {
if(Time.frameCount<number_of_points){
newPos = new Vector3(curPos.x,curPos.y-5,curPos.z-10);
newPos = rndVect(curPos,newPos);
linerender.SetPosition((int)Time.frameCount,newPos);
curPos = newPos;
}
}
private Vector3 rndVect(Vector3 start, Vector3 end)
{
return new Vector3(Random.Range(end.x, end.x),Random.Range(end.y+5f, end.y),Random.Range(end.z+20f, end.z));
}
}
using System.Collections;
public class lightining : MonoBehaviour {
private LineRenderer linerender;
public Color color=Color.black;
public float StartWidth=0.1f;
public float EndWidth=0.1f;
private Vector3 curPos;
private Vector3 newPos;
private Vector3 oldPos;
private int number_of_points=500;
// Use this for initialization
void Start () {
linerender = GetComponent("LineRenderer") as LineRenderer;
linerender.SetColors(color,color);
linerender.SetWidth(StartWidth,EndWidth);
linerender.SetVertexCount(number_of_points);
linerender.SetPosition(0,transform.position);
curPos=transform.position;
}
// Update is called once per frame
void Update () {
if(Time.frameCount<number_of_points){
newPos = new Vector3(curPos.x,curPos.y-5,curPos.z-10);
newPos = rndVect(curPos,newPos);
linerender.SetPosition((int)Time.frameCount,newPos);
curPos = newPos;
}
}
private Vector3 rndVect(Vector3 start, Vector3 end)
{
return new Vector3(Random.Range(end.x, end.x),Random.Range(end.y+5f, end.y),Random.Range(end.z+20f, end.z));
}
}