Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class Parallaxing : MonoBehaviour
- {
- #region variables
- private Transform cam;
- private Transform tr;
- private bool hasBuddy;
- #endregion
- void Start ()
- {
- tr = transform;
- hasBuddy = false;
- cam = Camera.main.transform;
- }
- void Update () {
- tr.position = new Vector3(tr.position.x - GetSpeed(), tr.position.y, tr.position.z);
- if (transform.position.x + renderer.bounds.size.x < cam.transform.position.x)
- {
- Destroy(this.gameObject);
- }
- else if (transform.position.x + renderer.bounds.size.x / 2 <= PlayerPrefs.GetFloat("CameraWidth") && !hasBuddy)
- {
- hasBuddy = true;
- GameObject newBuddy = Instantiate(tr.gameObject, new Vector3(tr.position.x + renderer.bounds.size.x, tr.position.y, tr.position.z), Quaternion.identity) as GameObject;
- newBuddy.transform.parent = tr.parent;
- newBuddy.transform.localScale = tr.localScale;
- }
- }
- float GetSpeed()
- {
- if (tr.gameObject.tag == "Ground")
- {
- return GameManager.GameSpeed / 2;
- }
- return GameManager.GameSpeed;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement