Skip to content

Commit f2b5cda

Browse files
Merge pull request #736 from StephenHodgson/HTK-Billboard
Updated billboard to use a target transform.
2 parents 55d6c1b + a173938 commit f2b5cda

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

Assets/HoloToolkit/Utilities/Scripts/Billboard.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,16 @@ public class Billboard : MonoBehaviour
2424
[Tooltip("Specifies the axis about which the object will rotate.")]
2525
public PivotAxis PivotAxis = PivotAxis.Free;
2626

27+
[Tooltip("Specifies the target we will orient to. If no Target is specified the main camera will be used.")]
28+
public Transform TargetTransform;
29+
2730
private void OnEnable()
2831
{
32+
if (TargetTransform == null)
33+
{
34+
TargetTransform = Camera.main.transform;
35+
}
36+
2937
Update();
3038
}
3139

@@ -34,13 +42,13 @@ private void OnEnable()
3442
/// </summary>
3543
private void Update()
3644
{
37-
if (!Camera.main)
45+
if (TargetTransform == null)
3846
{
3947
return;
4048
}
4149

4250
// Get a Vector that points from the target to the main camera.
43-
Vector3 directionToTarget = Camera.main.transform.position - transform.position;
51+
Vector3 directionToTarget = TargetTransform.position - transform.position;
4452

4553
// Adjust for the pivot axis.
4654
switch (PivotAxis)
@@ -65,4 +73,4 @@ private void Update()
6573
transform.rotation = Quaternion.LookRotation(-directionToTarget);
6674
}
6775
}
68-
}
76+
}

0 commit comments

Comments
 (0)