study/first_study/Assets/Player/Excution/SimpleSpeedLine.cs
jh04010421 339a595ac1 윤지호 | 유니티 연습
20226.01.27 수정 (태그 구현중, 오브젝트별 컴포넌트 배치필요)
2026-01-27 20:58:00 +09:00

34 lines
899 B
C#

using UnityEngine;
public class SimpleSpeedLine : MonoBehaviour
{
private LineRenderer LR;
public float fadespeed = 1f;
private float alpha = 1f;
public Vector3 playerpos1;
public Vector3 playerpos2;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
LR = GetComponent<LineRenderer>();
LR.positionCount = 2;
LR.SetPosition(1, playerpos1);
LR.SetPosition(0, playerpos2);
}
void Update()
{
if(alpha > 0)
{
alpha -= Time.deltaTime * fadespeed;
Gradient gradient = new Gradient();
gradient.SetKeys(LR.colorGradient.colorKeys, new GradientAlphaKey[] { new GradientAlphaKey(alpha, 0f), });
LR.colorGradient = gradient;
}
else
{
Destroy(gameObject);
}
}
}