Game Development Reference
In-Depth Information
1. using UnityEngine;
2. using System.Collections; 3.
4. public class Wrapper : MonoBehaviour { 5.
6.
//When the target moves out of these bounds,
7.
//it should be wrapped around the scene
8.
public Vector3 limits = new Vector3(10, 0, 10);
9.
10.
void Start () { 11.
12.
}
13.
14.
void Update () {
15.
//Get the current position
16.
Vector3 newPos = transform.position;
17.
18.
if(transform.position.x > limits.x){
19.
//Object left from the right, return it from the left
20.
newPos.x = -limits.x;
21.
}
22.
23.
if(transform.position.x < -limits.x){
24.
//Object left from the left, return it from the right
25.
newPos.x = limits.x;
26.
}
27.
28.
if(transform.position.z > limits.z){
29.
////Object left from the front, return it from the
back
30.
newPos.z = -limits.z;
31.
}
32.
33.
//Set the new position after the modifications
34.
transform.position = newPos;
Search WWH ::




Custom Search