Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //This script is attached to the Player1 object in the inspector.
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PlayerController : MonoBehaviour {
- //Horizonal Screen Wrap
- private Renderer[] renderers;
- private bool isWrappingX = false;
- void Start ()
- {
- //Horizontal Screen Wrap
- renderers = GetComponentsInChildren<Renderer>();
- }
- private void FixedUpdate()
- {
- ScreenWrap();
- }
- void ScreenWrap()
- {
- bool isVisible = CheckRenderers();
- print("GetComponents<Renderer>() = " + GetComponentsInChildren<Renderer>());
- print("isVisible = " + isVisible);
- //print("transform.position = " + transform.position);
- print("isWrappingX = " + isWrappingX);
- if(isVisible)
- {
- isWrappingX = false;
- print("isVisbile, returning");
- return;
- }
- Vector3 newPosition = transform.position;
- print("newPosition.x = " + newPosition.x);
- if(newPosition.x > 1 || newPosition.x < 0)
- {
- newPosition.x = -newPosition.x;
- print("isWrappingX is true, wrapping X");
- isWrappingX = true;
- }
- transform.position = newPosition;
- }
- bool CheckRenderers()
- {
- foreach(Renderer renderer in renderers)
- {
- if(renderer.isVisible)
- {
- return true;
- }
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement