@@ -67,11 +67,7 @@ private void SetupOptions()
67
67
conveyorSpeed . RegisterValueChangedCallback ( evt =>
68
68
{
69
69
m_ConveyorSpeed = evt . newValue ;
70
-
71
- // Update the tangent speed.
72
- var surfaceMaterial = m_ConveyorBeltShape . surfaceMaterial ;
73
- surfaceMaterial . tangentSpeed = m_ConveyorSpeed ;
74
- m_ConveyorBeltShape . surfaceMaterial = surfaceMaterial ;
70
+ UpdateConveyorSpeed ( ) ;
75
71
} ) ;
76
72
77
73
// Conveyor Angle.
@@ -80,9 +76,7 @@ private void SetupOptions()
80
76
conveyorAngle . RegisterValueChangedCallback ( evt =>
81
77
{
82
78
m_ConveyorAngle = evt . newValue ;
83
-
84
- // Update the conveyor angle.
85
- m_ConveyorBeltBody . rotation = new PhysicsRotate ( PhysicsMath . ToRadians ( m_ConveyorAngle ) ) ;
79
+ UpdateConveyorAngle ( ) ;
86
80
} ) ;
87
81
88
82
// Spawn.
@@ -119,10 +113,10 @@ private void SetupScene()
119
113
120
114
// Platform.
121
115
{
122
- m_ConveyorBeltBody = m_PhysicsWorld . CreateBody ( new PhysicsBodyDefinition { position = Vector2 . up * 8f } ) ;
116
+ m_ConveyorBeltBody = m_PhysicsWorld . CreateBody ( new PhysicsBodyDefinition { position = Vector2 . up * 8f , rotation = new PhysicsRotate ( PhysicsMath . ToRadians ( m_ConveyorAngle ) ) } ) ;
123
117
124
118
var geometry = PolygonGeometry . CreateBox ( new Vector2 ( 20f , 0.5f ) , 0.25f ) ;
125
- var shapeDef = new PhysicsShapeDefinition { surfaceMaterial = new PhysicsShape . SurfaceMaterial { friction = 0.8f , tangentSpeed = 2f } } ;
119
+ var shapeDef = new PhysicsShapeDefinition { surfaceMaterial = new PhysicsShape . SurfaceMaterial { friction = 0.8f , tangentSpeed = m_ConveyorSpeed } } ;
126
120
m_ConveyorBeltShape = m_ConveyorBeltBody . CreateShape ( geometry , shapeDef ) ;
127
121
}
128
122
@@ -146,4 +140,18 @@ private void Spawn(int spawnCount)
146
140
body . CreateShape ( PolygonGeometry . CreateBox ( Vector2 . one * scale , radius ) ) ;
147
141
}
148
142
}
143
+
144
+ private void UpdateConveyorAngle ( )
145
+ {
146
+ // Update the conveyor angle.
147
+ m_ConveyorBeltBody . rotation = new PhysicsRotate ( PhysicsMath . ToRadians ( m_ConveyorAngle ) ) ;
148
+ }
149
+
150
+ private void UpdateConveyorSpeed ( )
151
+ {
152
+ // Update the tangent speed.
153
+ var surfaceMaterial = m_ConveyorBeltShape . surfaceMaterial ;
154
+ surfaceMaterial . tangentSpeed = m_ConveyorSpeed ;
155
+ m_ConveyorBeltShape . surfaceMaterial = surfaceMaterial ;
156
+ }
149
157
}
0 commit comments