粒子碰撞检测
void OnParticleCollision(GameObject other){
}
拖尾渲染
using Unity Engine;
usingSystem.Collections;
publicclassPlayerScript:MonoBehaviour{
private Animator animator;
int attack;
private TrailRenderer trailRender;
voidStart( ){
animator=GetComponent
attack=Animator.StringToHash("Attack");
trailRender=GetComponentInChildren
}
voidUpdate( ){
if(Input.GetMouseButtonDown(0)){
animator.SetTrigger(attack);
}
}
void TrailActive( ){
trailRender.enabled=true;//开始攻击时,渲染开始
}
void TrailNoActive( ){
trailRender.enabled=false;//攻击结束时,渲染结束
}
}
线性渲染
lineRenderer.SetVertexCount(2);//先设置定点数量(方法)
(lineRenderer.positionCount=2; )(新版本属性)
lineRenderer.SetPosition(0,transform.position);//设置第一个定点位置
linrRenderer.SetPosition(1,targetTransform.position);//设置第二个定点位置
导航线性渲染结合(lineRenderer组件要挂载在第一个定点上)
usingUnityEngine;
usingSystem.Collections;
publicclassLineRendererScript:MonoBehaviour{
private NavMeshAgent agent;
private LineRenderer line;
public Transform startPoint;
public Transform endPoint;
voidStart( ){
agent=GetComponent
line=startPoint.gameObject.GetComponent
}
voidUpdate(){
if(line&&agent){
//生成一个导航网格的路径的变量,用来存储导航路径的相关信息
NavMeshPath path=new NavMeshPath( );
//计算路径,得到路径的相关信息,并且存储到path中
agent.CalculatePath(endPoint.position,path);
//根据path中的拐点来设置lineRenderer的相关属性
line.SetWidth(0.5f,0.5f);
line.SetColors(Color.red,Color.green);
//1.根据拐点数来设置顶点数
line.SetVertexCount(path.corners.Length+2);
//2.设置开始点和结束点
line.SetPosition(0,startPoint.position);
line.SetPosition(path.corners.Length+1,endPoint.position);
//设置其他顶点
for(inti=1;i<=path.corners.Length;++i){
line.SetPosition(i,path.corners[i-1]);
}
}
}
}
画线(挂载在起点物体)
usingUnityEngine;
usingSystem.Collections;
publicclassDrawLine:MonoBehaviour{
LineRenderer line;
//当前顶点下标
int index=1;
//顶点数
int countOfLine=1;
RaycastHit hit;
voidStart(){
line=GetComponent
line.SetVertexCount(1);
line.SetPosition(0,transform.position);
}
voidUpdate(){
if(Input.GetMouseButtonDown(0)){
if(Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition),outhit)){
if(hit.collider.name=="Plane"){
countOfLine++;
line.SetVertexCount(countOfLine);
if(index line.SetPosition(index,hit.point); index++; } } } } } }