5.15拖尾渲染,線(xiàn)性渲染

粒子碰撞檢測(cè)

void OnParticleCollision(GameObject? other){

}

拖尾渲染

using Unity Engine;

usingSystem.Collections;

publicclassPlayerScript:MonoBehaviour{

private? Animator? animator;

int? attack;

private TrailRenderer? trailRender;

voidStart( ){

animator=GetComponent<Animator>( );

attack=Animator.StringToHash("Attack");

trailRender=GetComponentInChildren<TrailRenderer>( );//獲取子物體的組件

}

voidUpdate( ){

if(Input.GetMouseButtonDown(0)){

animator.SetTrigger(attack);

}

}

void TrailActive( ){

trailRender.enabled=true;//開(kāi)始攻擊時(shí),渲染開(kāi)始

}

void TrailNoActive( ){

trailRender.enabled=false;//攻擊結(jié)束時(shí),渲染結(jié)束

}

}

線(xiàn)性渲染

lineRenderer.SetVertexCount(2);//先設(shè)置定點(diǎn)數(shù)量(方法)

(lineRenderer.positionCount=2; )(新版本屬性)

lineRenderer.SetPosition(0,transform.position);//設(shè)置第一個(gè)定點(diǎn)位置

linrRenderer.SetPosition(1,targetTransform.position);//設(shè)置第二個(gè)定點(diǎn)位置


導(dǎo)航線(xiàn)性渲染結(jié)合(lineRenderer組件要掛載在第一個(gè)定點(diǎn)上)

usingUnityEngine;

usingSystem.Collections;

publicclassLineRendererScript:MonoBehaviour{

private NavMeshAgent agent;

private LineRenderer line;

public? Transform? startPoint;

public? Transform? endPoint;

voidStart( ){

agent=GetComponent<NavMeshAgent>( );

line=startPoint.gameObject.GetComponent<LineRenderer>( );

}

voidUpdate(){

if(line&&agent){

//生成一個(gè)導(dǎo)航網(wǎng)格的路徑的變量,用來(lái)存儲(chǔ)導(dǎo)航路徑的相關(guān)信息

NavMeshPath?? path=new? NavMeshPath( );

//計(jì)算路徑,得到路徑的相關(guān)信息,并且存儲(chǔ)到path中

agent.CalculatePath(endPoint.position,path);

//根據(jù)path中的拐點(diǎn)來(lái)設(shè)置lineRenderer的相關(guān)屬性

line.SetWidth(0.5f,0.5f);

line.SetColors(Color.red,Color.green);

//1.根據(jù)拐點(diǎn)數(shù)來(lái)設(shè)置頂點(diǎn)數(shù)

line.SetVertexCount(path.corners.Length+2);

//2.設(shè)置開(kāi)始點(diǎn)和結(jié)束點(diǎn)

line.SetPosition(0,startPoint.position);

line.SetPosition(path.corners.Length+1,endPoint.position);

//設(shè)置其他頂點(diǎn)

for(inti=1;i<=path.corners.Length;++i){

line.SetPosition(i,path.corners[i-1]);

}

}

}

}

畫(huà)線(xiàn)(掛載在起點(diǎn)物體)

usingUnityEngine;

usingSystem.Collections;

publicclassDrawLine:MonoBehaviour{

LineRenderer line;

//當(dāng)前頂點(diǎn)下標(biāo)

int index=1;

//頂點(diǎn)數(shù)

int countOfLine=1;

RaycastHit hit;

voidStart(){

line=GetComponent<LineRenderer>( );

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<countOfLine){

line.SetPosition(index,hit.point);

index++;

}

}

}

}

}

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容