Version: 2021.1
LanguageEnglish
  • C#

TrailRenderer.widthMultiplier

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Switch to Manual
public float widthMultiplier;

Description

Set an overall multiplier that is applied to the TrailRenderer.widthCurve to get the final width of the trail.

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { public float width = 1.0f; public bool useCurve = true; private TrailRenderer tr;

void Start() { tr = GetComponent<TrailRenderer>(); tr.material = new Material(Shader.Find("Sprites/Default")); }

void Update() { AnimationCurve curve = new AnimationCurve(); if (useCurve) { curve.AddKey(0.0f, 0.0f); curve.AddKey(1.0f, 1.0f); } else { curve.AddKey(0.0f, 1.0f); curve.AddKey(1.0f, 1.0f); }

tr.widthCurve = curve; tr.widthMultiplier = width; tr.transform.position = new Vector3(Mathf.Sin(Time.time * 1.51f) * 7.0f, Mathf.Cos(Time.time * 1.27f) * 4.0f, 0.0f); }

void OnGUI() { GUI.Label(new Rect(25, 20, 200, 30), "Width"); width = GUI.HorizontalSlider(new Rect(125, 25, 200, 30), width, 0.1f, 1.0f); useCurve = GUI.Toggle(new Rect(25, 65, 200, 30), useCurve, "Use Curve"); } }