[Unity] 정지 개체 뒤에 궤적 확장하기
6812 단어 Unity
이럴 때는'움직이는 느낌'을 표현하기 위해 트레일 렌더가 스스로 움직이지 않으면 트레일이 생기지 않는다.
따라서 Line Renderer를 사용하여 자신의 뒤에 경로를 만듭니다.
먼저 궤적의 시작점으로 빈 객체를 준비합니다.
링크를 연결합니다.
다음 스크립트를 같은 대상에 부속합니다
InvTrail.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class InvTrail : MonoBehaviour {
[SerializeField] float m_spd=10f;
[SerializeField] int m_positionCount = 50;
LineRenderer m_lr;
Vector3[] m_oldPos;
int m_cnt;
// Use this for initialization
void Start () {
m_lr = GetComponent<LineRenderer>();
if (!m_lr)
Destroy(this);
m_lr.positionCount = m_positionCount;
m_oldPos = new Vector3[m_lr.positionCount];
for (int i = 0; i < m_oldPos.Length; ++i)
{
m_oldPos[i] = transform.position;
}
m_lr.SetPositions(m_oldPos);
m_cnt = m_oldPos.Length - 1;
}
// Update is called once per frame
void Update () {
Vector3 wSpd = transform.rotation * Vector3.back * m_spd;
m_cnt = Mathf.Max(0,m_cnt - 1);
for (int i = m_oldPos.Length-1; i > m_cnt; --i)
{
m_oldPos[i] = m_oldPos[i-1]+wSpd*Time.deltaTime;
}
m_oldPos[m_cnt] = transform.position;
m_lr.SetPositions(m_oldPos);
}
}
객체 뒤에 궤적 그리기재료 및 모양새 이동 속도 등 매개변수 조정
m_spd는 외관의 속도, mpositionCount는 궤적의 정점 수입니다.
Reference
이 문제에 관하여([Unity] 정지 개체 뒤에 궤적 확장하기), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/ELIXIR/items/f8223df28adaae3a6e7d텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)