# STrailRenderer

**成员** 22

|      |                                         |                                                                                                                                               |
| ---- | --------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
| 函数 | [Clear](#clear)                         | –                                                                                                                                             |
| 函数 | [GetPosition](#getposition)             | Get the position of a vertex in the trail.                                                                                                    |
| 属性 | [Enabled](#enabled)                     | Whether this TrailRenderer component is Enabled.                                                                                              |
| 属性 | [ReceiveShadows](#receiveshadows)       | Does this object receive shadows?                                                                                                             |
| 属性 | [IsVisible](#isvisible)                 | Is this renderer visible in any camera?                                                                                                       |
| 属性 | [CastShadows](#castshadows)             | Does the trail cast a shadow when a shadow-casting Light shines on it?                                                                        |
| 属性 | [MotionVectors](#motionvectors)         | Set whether to use motion vectors to track this Renderer’s per-pixel, screen-space motion from one frame to the next.                         |
| 属性 | [UseLightProbes](#uselightprobes)       | Enable Light Probes on the trail.                                                                                                             |
| 属性 | [Time](#time)                           | How long does the trail take to fade out. (seconds)                                                                                           |
| 属性 | [StartWidth](#startwidth)               | The width of the trail at the spawning point.                                                                                                 |
| 属性 | [EndWidth](#endwidth)                   | The width of the trail at the end of the trail.                                                                                               |
| 属性 | [WidthMultiplier](#widthmultiplier)     | Set an overall multiplier that is applied to the TrailRenderer.widthCurve to get the final width of the trail.                                |
| 属性 | [StartColor](#startcolor)               | Set the color at the start of the trail.                                                                                                      |
| 属性 | [EndColor](#endcolor)                   | Set the color at the end of the trail.                                                                                                        |
| 属性 | [Autodestruct](#autodestruct)           | Does the GameObject of this Trail Renderer auto destruct?                                                                                     |
| 属性 | [NumCornerVertices](#numcornervertices) | Set this to a value greater than 0, to get rounded corners between each segment of the trail.                                                 |
| 属性 | [NumCapVertices](#numcapvertices)       | Set this to a value greater than 0, to get rounded corners on each end of the trail.                                                          |
| 属性 | [MinVertexDistance](#minvertexdistance) | Set the minimum distance the trail can travel before a new vertex is added to it.                                                             |
| 属性 | [TextureMode](#texturemode)             | Choose whether the U coordinate of the trail texture is tiled or stretched. 0 Stretch, 1 Tile, 2 Distribute Per Segment, 3 Repeat Per Segment |
| 属性 | [Alignment](#alignment)                 | –                                                                                                                                             |
| 属性 | [PositionCount](#positioncount)         | Get the number of line segments in the trail.                                                                                                 |
| 属性 | [GameObject](#gameobject)               | –                                                                                                                                             |

## 函数

### Clear

void Clear()

返回值

`void`

示例

**Lua**

```lua
Space.Host.ExecutingObject.TrailRenderer.Clear()

```

### GetPosition

[SVector](/docs/zh-Hans/scripting/client-scripting-api-reference/types/svector.md) GetPosition(int index)

Get the position of a vertex in the trail.

参数

| 名称  | 类型 | 默认值 |
| ----- | ---- | ------ |
| index | int  | –      |

返回值

`SVector`

示例

**Lua**

```lua
vectorPos = Space.Host.ExecutingObject.TrailRenderer.GetPosition(0)

```

## 属性

### Enabled

bool Enabled {get; set; }

Whether this TrailRenderer component is Enabled.

示例

**Lua**

```lua
Space.Host.ExecutingObject.TrailRenderer.Enabled = true

```

**Lua**

```lua
--Clicking the object Enables/Disables the Trail Renderer component on this object  
--[Add "trailrenderer" reference to the Scripting Runtime component]

thisGameObject = Space.Host.ExecutingObject
trailrenderer = Space.Host.GetReference("trailrenderer").TrailRenderer


OnClick = function()
trailrenderer.Enabled =  not trailrenderer.Enabled
end


thisGameObject.AddClickable()
thisGameObject.Clickable.OnClick(OnClick)

```

### ReceiveShadows

bool ReceiveShadows {get; set; }

Does this object receive shadows?

示例

**Lua**

```lua
Space.Host.ExecutingObject.TrailRenderer.ReceiveShadows = true

```

**Lua**

```lua
--Make a UIToggle disable/enable the Receive Shadows feature of a Trail Renderer
--[Add "toggle" and "trailrenderer" references to the Scripting Runtime component]

thisGameObject = Space.Host.ExecutingObject

toggle = Space.Host.GetReference("toggle").UIToggle 
trailrenderer = Space.Host.GetReference("trailrenderer").TrailRenderer

toggle.IsOn = trailrenderer.ReceiveShadows  --make toggle start at correct state

OVC = function()
  if toggle.IsOn then
    trailrenderer.ReceiveShadows  = true
  else
    trailrenderer.ReceiveShadows  = false
  end
end

toggle.OnValueChanged(OVC)

```

### IsVisible

bool IsVisible {get; }

Is this renderer visible in any camera?

示例

**Lua**

```lua
Space.Log(Space.Host.ExecutingObject.TrailRenderer.IsVisible)

```

### CastShadows

bool CastShadows {get; set; }

Does the trail cast a shadow when a shadow-casting Light shines on it?

示例

**Lua**

```lua
Space.Host.ExecutingObject.TrailRenderer.CastShadows = true

```

**Lua**

```lua
--Make a UIToggle disable/enable the Cast Shadows feature of a Trail Renderer
--[Add "toggle" and "trailrenderer" references to the Scripting Runtime component]

thisGameObject = Space.Host.ExecutingObject

toggle = Space.Host.GetReference("toggle").UIToggle 
trailrenderer = Space.Host.GetReference("trailrenderer").TrailRenderer

toggle.IsOn = trailrenderer.CastShadows  --make toggle start at correct state

OVC = function()
  if toggle.IsOn then
    trailrenderer.CastShadows  = true
  else
    trailrenderer.CastShadows  = false
  end
end

toggle.OnValueChanged(OVC)

```

### MotionVectors

bool MotionVectors {get; set; }

Set whether to use motion vectors to track this Renderer’s per-pixel, screen-space motion from one frame to the next. You can use this information to apply post-processing effects such as motion blur.

示例

**Lua**

```lua
Space.Host.ExecutingObject.TrailRenderer.MotionVectors = true

```

**Lua**

```lua
--Make a UIToggle disable/enable the Motion Vectors feature of a Trail Renderer
--[Add "toggle" and "trailrenderer" references to the Scripting Runtime component]

thisGameObject = Space.Host.ExecutingObject

toggle = Space.Host.GetReference("toggle").UIToggle 
trailrenderer = Space.Host.GetReference("trailrenderer").TrailRenderer

toggle.IsOn = trailrenderer.MotionVectors  --make toggle start at correct state

OVC = function()
  if toggle.IsOn then
    trailrenderer.MotionVectors  = true
  else
    trailrenderer.MotionVectors  = false
  end
end

toggle.OnValueChanged(OVC)

```

### UseLightProbes

bool UseLightProbes {get; set; }

Enable Light Probes on the trail.

示例

**Lua**

```lua
Space.Host.ExecutingObject.TrailRenderer.UseLightProbes = true

```

**Lua**

```lua
--Make a UIToggle disable/enable the Light Probes feature of a Trail Renderer
--[Add "toggle" and "trailrenderer" references to the Scripting Runtime component]

thisGameObject = Space.Host.ExecutingObject

toggle = Space.Host.GetReference("toggle").UIToggle 
trailrenderer = Space.Host.GetReference("trailrenderer").TrailRenderer

toggle.IsOn = trailrenderer.UseLightProbes  --make toggle start at correct state

OVC = function()
  if toggle.IsOn then
    trailrenderer.UseLightProbes  = true
  else
    trailrenderer.UseLightProbes  = false
  end
end

toggle.OnValueChanged(OVC)

```

### Time

float Time {get; set; }

How long does the trail take to fade out. (seconds)

示例

**Lua**

```lua
Space.Host.ExecutingObject.TrailRenderer.Time = 10

```

**Lua**

```lua
--Make a slider change the Trail Renderer's Time
--[Add "slider" and "trailrenderer" references to the Scripting Runtime component]

thisGameObject = Space.Host.ExecutingObject

slider = Space.Host.GetReference("slider").UISlider
trailrenderer = Space.Host.GetReference("trailrenderer").TrailRenderer


OVC = function()
trailrenderer.Time = slider.Value * 10 --0 to 10
end

slider.OnValueChanged(OVC)

```

### StartWidth

float StartWidth {get; set; }

The width of the trail at the spawning point. A width of 1 corresponds to 1 unit in the game world.

示例

**Lua**

```lua
Space.Host.ExecutingObject.TrailRenderer.StartWidth = 1.1

```

**Lua**

```lua
--Make a slider change the Trail Renderer's Start Width
--[Add "slider" and "trailrenderer" references to the Scripting Runtime component]

thisGameObject = Space.Host.ExecutingObject

slider = Space.Host.GetReference("slider").UISlider
trailrenderer = Space.Host.GetReference("trailrenderer").TrailRenderer


OVC = function()
trailrenderer.StartWidth = slider.Value * 10 --0 to 10
end

slider.OnValueChanged(OVC)

```

### EndWidth

float EndWidth {get; set; }

The width of the trail at the end of the trail. A width of 1 corresponds to 1 unit in the game world.

示例

**Lua**

```lua
Space.Host.ExecutingObject.TrailRenderer.EndWidth = 0.1

```

**Lua**

```lua
--Make a slider change the Trail Renderer's End Width
--[Add "slider" and "trailrenderer" references to the Scripting Runtime component]

thisGameObject = Space.Host.ExecutingObject

slider = Space.Host.GetReference("slider").UISlider
trailrenderer = Space.Host.GetReference("trailrenderer").TrailRenderer


OVC = function()
trailrenderer.EndWidth = slider.Value * 10 --0 to 10
end

slider.OnValueChanged(OVC)

```

### WidthMultiplier

float WidthMultiplier {get; set; }

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

示例

**Lua**

```lua
Space.Host.ExecutingObject.TrailRenderer.WidthMultiplier = 2

```

**Lua**

```lua
--Make a slider change the Trail Renderer's Width Multiplier
--[Add "slider" and "trailrenderer" references to the Scripting Runtime component]

thisGameObject = Space.Host.ExecutingObject

slider = Space.Host.GetReference("slider").UISlider
trailrenderer = Space.Host.GetReference("trailrenderer").TrailRenderer


OVC = function()
trailrenderer.WidthMultiplier = slider.Value * 10 --0 to 10
end

slider.OnValueChanged(OVC)

```

### StartColor

[SColor](/docs/zh-Hans/scripting/client-scripting-api-reference/types/scolor.md) StartColor {get; set; }

Set the color at the start of the trail.

示例

**Lua**

```lua
Space.Host.ExecutingObject.TrailRenderer.StartColor = Color.Black

```

**Lua**

```lua
--makes UIButton open a color picker to change TrailRenderer's Start Color
--[Add "button" and "trailrenderer" references to the Scripting Runtime component]

button = Space.Host.GetReference("button").UIButton 
trailrenderer = Space.Host.GetReference("trailrenderer").TrailRenderer
originalColor = trailrenderer.StartColor

OnChange = function(SColor) 
 trailrenderer.StartColor = SColor
end

OnSelect = function(SColor)
 trailrenderer.StartColor = SColor
end

OnCancel = function()
  trailrenderer.StartColor = originalColor 
end

OnClick = function()
Space.Dialogues.ColorPicker("title","okbutton", OnChange, OnSelect, OnCancel, originalColor)
end


button.OnClick(OnClick)

```

### EndColor

[SColor](/docs/zh-Hans/scripting/client-scripting-api-reference/types/scolor.md) EndColor {get; set; }

Set the color at the end of the trail.

示例

**Lua**

```lua
Space.Host.ExecutingObject.TrailRenderer.EndColor = Color.Red

```

**Lua**

```lua
--makes UIButton open a color picker to change TrailRenderer's End Color
--[Add "button" and "trailrenderer" references to the Scripting Runtime component]

button = Space.Host.GetReference("button").UIButton 
trailrenderer = Space.Host.GetReference("trailrenderer").TrailRenderer
originalColor = trailrenderer.EndColor

OnChange = function(SColor) 
 trailrenderer.EndColor = SColor
end

OnSelect = function(SColor)
 trailrenderer.EndColor = SColor
end

OnCancel = function()
  trailrenderer.EndColor = originalColor 
end

OnClick = function()
Space.Dialogues.ColorPicker("title","okbutton", OnChange, OnSelect, OnCancel, originalColor)
end


button.OnClick(OnClick)

```

### Autodestruct

bool Autodestruct {get; set; }

Does the GameObject of this Trail Renderer auto destruct?

示例

**Lua**

```lua
Space.Host.ExecutingObject.TrailRenderer.Autodestruct = true

```

**Lua**

```lua
--Make a UIToggle disable/enable the Autodestruct feature of a Trail Renderer
--[Add "toggle" and "trailrenderer" references to the Scripting Runtime component]

thisGameObject = Space.Host.ExecutingObject

toggle = Space.Host.GetReference("toggle").UIToggle 
trailrenderer = Space.Host.GetReference("trailrenderer").TrailRenderer

toggle.IsOn = trailrenderer.Autodestruct  --make toggle start at correct state

OVC = function()
  if toggle.IsOn then
    trailrenderer.Autodestruct  = true
  else
    trailrenderer.Autodestruct  = false
  end
end

toggle.OnValueChanged(OVC)

```

### NumCornerVertices

int NumCornerVertices {get; set; }

Set this to a value greater than 0, to get rounded corners between each segment of the trail.

示例

**Lua**

```lua
Space.Host.ExecutingObject.TrailRenderer.NumCornerVertices = 2

```

**Lua**

```lua
--Make a slider change the Trail Renderer's Number of Corner Vertices
--[Add "slider" and "trailrenderer" references to the Scripting Runtime component]

thisGameObject = Space.Host.ExecutingObject

slider = Space.Host.GetReference("slider").UISlider
trailrenderer = Space.Host.GetReference("trailrenderer").TrailRenderer


OVC = function()
trailrenderer.NumCornerVertices = slider.Value * 90 --0 to 90
end

slider.OnValueChanged(OVC)

```

### NumCapVertices

int NumCapVertices {get; set; }

Set this to a value greater than 0, to get rounded corners on each end of the trail.

示例

**Lua**

```lua
Space.Host.ExecutingObject.TrailRenderer.NumCapVertices = 3

```

**Lua**

```lua
--Make a slider change the Trail Renderer's Number of End Cap Vertices
--[Add "slider" and "trailrenderer" references to the Scripting Runtime component]

thisGameObject = Space.Host.ExecutingObject

slider = Space.Host.GetReference("slider").UISlider
trailrenderer = Space.Host.GetReference("trailrenderer").TrailRenderer


OVC = function()
trailrenderer.NumCapVertices = slider.Value * 90 --0 to 90
end

slider.OnValueChanged(OVC)

```

### MinVertexDistance

float MinVertexDistance {get; set; }

Set the minimum distance the trail can travel before a new vertex is added to it. Smaller values with give smoother trails, consisting of more vertices, but costing more performance.

示例

**Lua**

```lua
Space.Host.ExecutingObject.TrailRenderer.MinVertexDistance = 1

```

**Lua**

```lua
--Make a slider change the Trail Renderer's Number of Mininum Vertex Distance
--[Add "slider" and "trailrenderer" references to the Scripting Runtime component]

thisGameObject = Space.Host.ExecutingObject

slider = Space.Host.GetReference("slider").UISlider
trailrenderer = Space.Host.GetReference("trailrenderer").TrailRenderer


OVC = function()
trailrenderer.MinVertexDistance = slider.Value * 10 --0 to 10
end

slider.OnValueChanged(OVC)

```

### TextureMode

int TextureMode {get; set; }

Choose whether the U coordinate of the trail texture is tiled or stretched. 0 Stretch, 1 Tile, 2 Distribute Per Segment, 3 Repeat Per Segment

示例

**Lua**

```lua
Space.Host.ExecutingObject.TrailRenderer.TextureMode = 2

```

**Lua**

```lua
--Clicking the object toggles between TrailRenderer's 4 different Texture Modes
--[Add "trailrenderer" reference to the Scripting Runtime component]

thisGameObject = Space.Host.ExecutingObject
trailrenderer = Space.Host.GetReference("trailrenderer").TrailRenderer


OnClick = function()
  if trailrenderer.TextureMode == 3 then
    trailrenderer.TextureMode = 0
  else
    trailrenderer.TextureMode = trailrenderer.TextureMode + 1
  end
end


thisGameObject.AddClickable()
thisGameObject.Clickable.OnClick(OnClick)

```

### Alignment

int Alignment {get; set; }

示例

**Lua**

```lua
Space.Host.ExecutingObject.TrailRenderer.Alignment = 1

```

**Lua**

```lua
--Clicking the object toggles between TrailRenderer's View or Transform Z alignment
--[Add "trailrenderer" reference to the Scripting Runtime component]

thisGameObject = Space.Host.ExecutingObject
trailrenderer = Space.Host.GetReference("trailrenderer").TrailRenderer


OnClick = function()
  if trailrenderer.Alignment == 0 then
    trailrenderer.Alignment = 1
  else
    trailrenderer.Alignment = 0
  end
end


thisGameObject.AddClickable()
thisGameObject.Clickable.OnClick(OnClick)

```

### PositionCount

int PositionCount {get; }

Get the number of line segments in the trail.

示例

**Lua**

```lua
numLineSegments = Space.Host.ExecutingObject.TrailRenderer.PositionCount

```

### GameObject

SGameObject GameObject {get; }

示例

**Lua**

```lua
theGameObject = Space.Host.ExecutingObject.TrailRenderer.GameObject

```
