Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2018
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class FloorManager : MonoBehaviour {
  5. public Transform[] m_aFloorParts;
  6. public float m_fFloorStartZ;
  7. public float m_fFloorEndZ;
  8. public float m_fMovementSpeed;
  9. void Start () {
  10. float fZpos = 0.0f;
  11. float fFloorLength = Mathf.Abs(m_fFloorStartZ) + Mathf.Abs(m_fFloorEndZ);
  12. Debug.Log("Floor Length is: " + fFloorLength.ToString());
  13.  
  14. while(fZpos > -fFloorLength) {
  15. SpawnNewFloor(fZpos);
  16. fZpos -= 5.0f;
  17. }
  18. }
  19. public void SpawnNewFloor(float fZOffset) {
  20. Debug.Log(fZOffset);
  21. Transform tFloorT = Instantiate(
  22. m_aFloorParts[Random.Range(0, m_aFloorParts.Length - 1)],
  23. new Vector3(0.0f, 0.0f, m_fFloorStartZ + fZOffset),
  24. Quaternion.identity);
  25. if( null == tFloorT){
  26. Debug.LogError("Unable to spawn!");
  27. return;
  28. }
  29. ScrollingItem gcFloorPart = tFloorT.GetComponent<ScrollingItem>();
  30. if(null == gcFloorPart){
  31. Debug.LogError("Prefab doesn't have a Scrolling Item component.");
  32. return;
  33. }
  34. gcFloorPart.m_fEndZ = m_fFloorEndZ;
  35. gcFloorPart.m_fStartZ = m_fFloorStartZ + fZOffset;
  36. gcFloorPart.m_fMovementSpeed = m_fMovementSpeed;
  37.  
  38. }
  39.  
  40. // Update is called once per frame
  41. void Update () {
  42.  
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement