Skip to content

Commit d39ac32

Browse files
committed
Updated to support Unity 6 (built in 6000.0.40f1)
1 parent 3a37f62 commit d39ac32

File tree

8 files changed

+603
-340
lines changed

8 files changed

+603
-340
lines changed

Assets/CameraMultiTarget/Example/Example.unity

Lines changed: 341 additions & 104 deletions
Large diffs are not rendered by default.
Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,35 @@
1-
using System.Collections;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using UnityEngine;
5-
6-
public class ExampleGameController : MonoBehaviour
7-
{
8-
public CameraMultiTarget cameraMultiTarget;
9-
public GameObject targetPrefab;
10-
11-
private IEnumerator Start() {
12-
var numberOfTargets = 3;
13-
var targets = new List<GameObject>(numberOfTargets);
14-
targets.Add(CreateTarget());
15-
cameraMultiTarget.SetTargets(targets.ToArray());
16-
foreach (var _ in Enumerable.Range(0, numberOfTargets - targets.Count)) {
17-
yield return new WaitForSeconds(5.0f);
18-
targets.Add(CreateTarget());
19-
cameraMultiTarget.SetTargets(targets.ToArray());
20-
}
21-
yield return null;
22-
}
23-
24-
private GameObject CreateTarget() {
25-
GameObject target = GameObject.Instantiate(targetPrefab);
26-
target.AddComponent<ExampleTargetBehaviour>();
27-
return target;
28-
}
29-
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using UnityEngine;
5+
6+
namespace Rockbyte.CMT.Examples.ExampleCameraMultiTarget
7+
{
8+
public class ExampleGameController : MonoBehaviour
9+
{
10+
public CameraMultiTarget cameraMultiTarget;
11+
public GameObject targetPrefab;
12+
13+
private IEnumerator Start()
14+
{
15+
var numberOfTargets = 3;
16+
var targets = new List<GameObject>(numberOfTargets);
17+
targets.Add(CreateTarget());
18+
cameraMultiTarget.SetTargets(targets.ToArray());
19+
foreach (var _ in Enumerable.Range(0, numberOfTargets - targets.Count))
20+
{
21+
yield return new WaitForSeconds(5.0f);
22+
targets.Add(CreateTarget());
23+
cameraMultiTarget.SetTargets(targets.ToArray());
24+
}
25+
yield return null;
26+
}
27+
28+
private GameObject CreateTarget()
29+
{
30+
GameObject target = GameObject.Instantiate(targetPrefab);
31+
target.AddComponent<ExampleTargetBehaviour>();
32+
return target;
33+
}
34+
}
3035
}
Lines changed: 41 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,42 @@
1-
using System.Collections;
2-
using UnityEngine;
3-
4-
public class ExampleTargetBehaviour : MonoBehaviour
5-
{
6-
private static readonly Vector3 MinPosition = new Vector3(-10f, 1f, -10f);
7-
private static readonly Vector3 MaxPosition = new Vector3(10f, 4f, 10f);
8-
9-
private Vector3 destinationPosition;
10-
11-
private void Awake() {
12-
transform.position = new Vector3(0f, 1.5f, 0f);
13-
destinationPosition = transform.position;
14-
}
15-
16-
private IEnumerator Start() {
17-
for(int i=0; i< 100; i++) {
18-
yield return new WaitForSeconds(5.0f);
19-
destinationPosition = GetRandomPosition();
20-
}
21-
}
22-
23-
private void Update() {
24-
transform.position = Vector3.Lerp(transform.position, destinationPosition, Time.deltaTime);
25-
}
26-
27-
private static Vector3 GetRandomPosition() {
28-
var randomPosition = new Vector3(
29-
Random.Range(MinPosition.x, MaxPosition.x),
30-
Random.Range(MinPosition.y, MaxPosition.y),
31-
Random.Range(MinPosition.z, MaxPosition.y));
32-
return randomPosition;
33-
}
1+
using System.Collections;
2+
using UnityEngine;
3+
4+
namespace Rockbyte.CMT.Examples.ExampleCameraMultiTarget
5+
{
6+
public class ExampleTargetBehaviour : MonoBehaviour
7+
{
8+
private static readonly Vector3 MinPosition = new Vector3(-10f, 1f, -10f);
9+
private static readonly Vector3 MaxPosition = new Vector3(10f, 4f, 10f);
10+
11+
private Vector3 destinationPosition;
12+
13+
private void Awake()
14+
{
15+
transform.position = new Vector3(0f, 1.5f, 0f);
16+
destinationPosition = transform.position;
17+
}
18+
19+
private IEnumerator Start()
20+
{
21+
for (int i = 0; i < 100; i++)
22+
{
23+
yield return new WaitForSeconds(5.0f);
24+
destinationPosition = GetRandomPosition();
25+
}
26+
}
27+
28+
private void Update()
29+
{
30+
transform.position = Vector3.Lerp(transform.position, destinationPosition, Time.deltaTime);
31+
}
32+
33+
private static Vector3 GetRandomPosition()
34+
{
35+
var randomPosition = new Vector3(
36+
Random.Range(MinPosition.x, MaxPosition.x),
37+
Random.Range(MinPosition.y, MaxPosition.y),
38+
Random.Range(MinPosition.z, MaxPosition.y));
39+
return randomPosition;
40+
}
41+
}
3442
}

0 commit comments

Comments
 (0)