# SJointSpring

**成员** 5

|      |                                   |                                                                           |
| ---- | --------------------------------- | ------------------------------------------------------------------------- |
| 函数 | [ToString](#tostring)             | Returns this SJointSpring's properties as a string                        |
| 函数 | [New](#new)                       | Creates a new SJointSpring with the given spring, damper, targetPosition. |
| 属性 | [Spring](#spring)                 | The spring forces used to reach the target position.                      |
| 属性 | [Damper](#damper)                 | The damper force uses to dampen the spring.                               |
| 属性 | [TargetPosition](#targetposition) | The target position the joint attempts to reach.                          |

## 函数

### ToString

override string ToString()

Returns this SJointSpring's properties as a string

返回值

`string`

示例

**Lua**

```lua
SpringString = Space.Host.ExecutingObject.HingeJoint.Spring.ToString()

```

**Lua**

```lua
--the below script will make a UI Text element display this GameObjects Hinge Joint Spring properties
--[Add "thetext" and "thehingejoint" reference to the Scripting Runtime component]
thisObject = Space.Host.ExecutingObject
text = Space.Host.GetReference("thetext").UIText
hingejoint = Space.Host.GetReference("thehingejoint").HingeJoint


function OnUpdateFunction()
spring = hingejoint.Spring
text.Text = spring.ToString()
end


thisObject.OnUpdate(OnUpdateFunction)

```

### New

static SJointSpring New(float spring, float damper, float targetPosition)

Creates a new SJointSpring with the given spring, damper, targetPosition.

参数

| 名称           | 类型  | 默认值 |
| -------------- | ----- | ------ |
| spring         | float | –      |
| damper         | float | –      |
| targetPosition | float | –      |

返回值

`SJointSpring`

示例

**Lua**

```lua
Motor= Space.Host.ExecutingObject.HingeJoint.Spring.New(1,2,3)

```

**Lua**

```lua
--the below script will change all Hinge Joint Spring properties to 0 when clicked
--[Add "thehingejoint" reference to the Scripting Runtime component]
thisObject = Space.Host.ExecutingObject
hingejoint = Space.Host.GetReference("thehingejoint").HingeJoint


function OnClickFunction() 
spring = hingejoint.Spring
hingejoint.Spring = spring .New(0,0,0)
end

thisObject.AddClickable()
thisObject.Clickable.OnClick(OnClickFunction)

```

## 属性

### Spring

float Spring {get; }

The spring forces used to reach the target position.

示例

**Lua**

```lua
SpringSpring= Space.Host.ExecutingObject.HingeJoint.Spring.Spring

```

**Lua**

```lua
--the below script will make a slider change a Hinge Joint Spring Spring property
--[Add "theslider" and "thehingejoint" reference to the Scripting Runtime component]

slider = Space.Host.GetReference("theslider").UISlider
hingejoint = Space.Host.GetReference("thehingejoint").HingeJoint


OVC = function()
spring = hingejoint.Spring
spring.Spring = (slider.Value * 10.0) -- from 0.0 to 10.0
hingejoint.Spring= spring
end

slider.OnValueChanged(OVC)

```

### Damper

float Damper {get; }

The damper force uses to dampen the spring.

示例

**Lua**

```lua
SpringDamper= Space.Host.ExecutingObject.HingeJoint.Spring.Damper

```

**Lua**

```lua
--the below script will make a slider change a Hinge Joint Spring Damper property
--[Add "theslider" and "thehingejoint" reference to the Scripting Runtime component]

slider = Space.Host.GetReference("theslider").UISlider
hingejoint = Space.Host.GetReference("thehingejoint").HingeJoint


OVC = function()
spring = hingejoint.Spring
spring.Damper = (slider.Value * 10.0) -- from 0.0 to 10.0
hingejoint.Spring = spring
end

slider.OnValueChanged(OVC)

```

### TargetPosition

float TargetPosition {get; }

The target position the joint attempts to reach.

示例

**Lua**

```lua
SpringTargetPosition = Space.Host.ExecutingObject.HingeJoint.Spring.TargetPosition

```

**Lua**

```lua
--the below script will make a slider change a Hinge Joint Spring TargetPosition property
--[Add "theslider" and "thehingejoint" reference to the Scripting Runtime component]

slider = Space.Host.GetReference("theslider").UISlider
hingejoint = Space.Host.GetReference("thehingejoint").HingeJoint


OVC = function()
spring = hingejoint.Spring
spring.TargetPosition = (slider.Value * 10.0) -- from 0.0 to 10.0
hingejoint.Spring = spring
end

slider.OnValueChanged(OVC)

```
