Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2020
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.65 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class EnviromentMovement : MonoBehaviour
  6. {
  7.  
  8.     [SerializeField]
  9.     private float speed;
  10.  
  11.     public GameObject spawnLand;
  12.     private GameObject currentLand;
  13.     private GameObject prevoiusLand;
  14.  
  15.     public Transform spawnPosition;
  16.     public Transform destroyPosition;
  17.  
  18.     private float spawnDistance;
  19.  
  20.     private Vector3 newPosition;
  21.  
  22.     private ObstaclesGeneration obstaclesGeneration;
  23.  
  24.     void Start()
  25.     {
  26.         obstaclesGeneration = new ObstaclesGeneration();
  27.         currentLand = GameManager.Instance.land.gameObject;
  28.         prevoiusLand = currentLand;
  29.     }
  30.  
  31.     void Update()
  32.     {
  33.         transform.position += new Vector3(0, 0, speed * Time.deltaTime);
  34.  
  35.         spawnDistance = currentLand.transform.localScale.z / 2;
  36.  
  37.  
  38.         if (currentLand.transform.position.z + spawnDistance < spawnPosition.position.z)
  39.         {
  40.             newPosition = currentLand.transform.position;
  41.             newPosition.z = currentLand.transform.localScale.z + currentLand.transform.position.z;
  42.             prevoiusLand = currentLand;
  43.             currentLand = Instantiate(spawnLand, newPosition, Quaternion.identity,transform);
  44.             GameManager.Instance.land = currentLand.transform;
  45.             obstaclesGeneration.GenerateObstacles1();
  46.                
  47.         }
  48.  
  49.         if ( prevoiusLand != null && prevoiusLand.transform.position.z < destroyPosition.position.z)
  50.         {
  51.             Destroy(prevoiusLand);
  52.         }
  53.  
  54.         if (GameManager.Instance.obstacles.Capacity > 0)
  55.             obstaclesGeneration.MoveObstacles(10f);
  56.  
  57.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement