Add Unity3D projects

This commit is contained in:
2024-03-09 19:25:59 +00:00
parent 1c71f24fab
commit 829289c881
4626 changed files with 441247 additions and 0 deletions

View File

@ -0,0 +1,41 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ScreenEdgeChecker : MonoBehaviour {
// inspector settings
public Rigidbody rigidBody;
public bool destroyWhenOffscreen = false;
//
// Use this for initialization
void Start () {
// start periodically checking for being off-screen
InvokeRepeating ("CheckScreenEdges", 0.1f, 0.1f);
}
private void CheckScreenEdges() {
Vector3 pos = transform.position;
Vector3 vel = rigidBody.velocity;
float xTeleport = 0f, zTeleport = 0f;
if (pos.x < GameManager.screenBottomLeft.x && vel.x <= 0f)
xTeleport = GameManager.screenWidth;
else if (pos.x > GameManager.screenTopRight.x && vel.x >= 0f)
xTeleport = -GameManager.screenWidth;
if (pos.z < GameManager.screenBottomLeft.z && vel.z <= 0f)
zTeleport = GameManager.screenHeight;
else if (pos.z > GameManager.screenTopRight.z && vel.z >= 0f)
zTeleport = -GameManager.screenHeight;
if (xTeleport != 0f || zTeleport != 0f) {
if (destroyWhenOffscreen)
Destroy (this.gameObject);
else
transform.position = new Vector3 (pos.x + xTeleport, 0f, pos.z + zTeleport);
}
}
}