Advertisement
Guest User

Untitled

a guest
May 20th, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.54 KB | None | 0 0
  1. //This script is attached to the Player1 object in the inspector.
  2.  
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6.  
  7. public class PlayerController : MonoBehaviour {
  8.  
  9.     //Horizonal Screen Wrap
  10.     private Renderer[] renderers;
  11.     private bool isWrappingX = false;
  12.  
  13.     void Start ()
  14.     {
  15.         //Horizontal Screen Wrap
  16.         renderers = GetComponentsInChildren<Renderer>();
  17.     }
  18.  
  19.     private void FixedUpdate()
  20.     {
  21.         ScreenWrap();
  22.     }
  23.  
  24.     void ScreenWrap()
  25.     {
  26.         bool isVisible = CheckRenderers();
  27.  
  28.         print("GetComponents<Renderer>() = " + GetComponentsInChildren<Renderer>());
  29.         print("isVisible = " + isVisible);
  30.         //print("transform.position = " + transform.position);
  31.         print("isWrappingX = " + isWrappingX);
  32.  
  33.         if(isVisible)
  34.         {
  35.             isWrappingX = false;
  36.             print("isVisbile, returning");
  37.             return;
  38.         }
  39.  
  40.         Vector3 newPosition = transform.position;
  41.  
  42.         print("newPosition.x = " + newPosition.x);
  43.  
  44.         if(newPosition.x > 1 || newPosition.x < 0)
  45.         {
  46.             newPosition.x = -newPosition.x;
  47.             print("isWrappingX is true, wrapping X");
  48.             isWrappingX = true;
  49.         }
  50.  
  51.         transform.position = newPosition;
  52.     }
  53.  
  54.     bool CheckRenderers()
  55.     {
  56.         foreach(Renderer renderer in renderers)
  57.         {
  58.             if(renderer.isVisible)
  59.             {
  60.                 return true;
  61.             }
  62.         }
  63.  
  64.         return false;
  65.  
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement