Advertisement
Guest User

Parallaxing.cs

a guest
Dec 11th, 2014
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.24 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class Parallaxing : MonoBehaviour
  5. {
  6.     #region variables
  7.     private Transform cam;
  8.  
  9.     private Transform tr;
  10.     private bool hasBuddy;
  11.     #endregion
  12.  
  13.     void Start ()
  14.     {
  15.         tr = transform;
  16.         hasBuddy = false;
  17.         cam = Camera.main.transform;
  18.     }
  19.  
  20.     void Update () {
  21.         tr.position = new Vector3(tr.position.x - GetSpeed(), tr.position.y, tr.position.z);
  22.         if (transform.position.x + renderer.bounds.size.x < cam.transform.position.x)
  23.         {
  24.             Destroy(this.gameObject);
  25.         }
  26.         else if (transform.position.x + renderer.bounds.size.x / 2 <= PlayerPrefs.GetFloat("CameraWidth") && !hasBuddy)
  27.         {
  28.             hasBuddy = true;
  29.             GameObject newBuddy = Instantiate(tr.gameObject, new Vector3(tr.position.x + renderer.bounds.size.x, tr.position.y, tr.position.z), Quaternion.identity) as GameObject;
  30.             newBuddy.transform.parent = tr.parent;
  31.             newBuddy.transform.localScale = tr.localScale;
  32.         }
  33.     }
  34.  
  35.     float GetSpeed()
  36.     {
  37.         if (tr.gameObject.tag == "Ground")
  38.         {
  39.             return GameManager.GameSpeed / 2;
  40.         }
  41.  
  42.         return GameManager.GameSpeed;
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement