Пример #1
0
 // Start is called before the first frame update
 void Start()
 {
     myRigidbody   = GetComponent <Rigidbody>();
     myAudioSource = GetComponent <AudioSource>();
     level         = FindObjectOfType <LevelHandle>();
     state         = State.Alive;
 }
Пример #2
0
        private void FixedUpdate()
        {
            // early-out: not importend if he hasn't crossed the threashhold of half the length
            if (target.position.z <= (currentLevel.transform.position.z + currentLevel.levelLength * threashHold))
            {
                return;
            }

            // dequeue old levels from the past
            if (loadedLevels.Count > queueLength)
            {
                Destroy(loadedLevels.Dequeue());
            }

            // choose next level part
            int        random = Random.Range(0, currentLevel.nextLevels.Length);
            GameObject tmp    = Instantiate(currentLevel.nextLevels[random]);

            // position next level part at the end of the current level
            tmp.transform.position = new Vector3(0, 0, currentLevel.transform.position.z + currentLevel.levelLength);

            // changing currentlevel to next level
            currentLevel = CheckNextLevel(tmp);
            loadedLevels.Enqueue(tmp);
        }
Пример #3
0
        void Start()
        {
#if UNITY_EDITOR
            if (!target)
            {
                Debug.LogError("FATAL: no taget to create levels for.");
                Destroy(this);
                return;
            }
            if (!startLevel)
            {
                Debug.LogError("FATAL: no start level to start travercing");
                Destroy(this);
                return;
            }
#endif
            // get start level
            currentLevel = CheckNextLevel(startLevel);
#if UNITY_EDITOR
            if (!currentLevel)
            {
                Destroy(this);
                return;
            }
#endif
            // adds start level to queue
            loadedLevels.Enqueue(startLevel);
        }
Пример #4
0
    // Update is called once per frame
    void Update()
    {
        if (rot.GetRotate())
        {
            GameObject r = rot.GetRot();
            if (r.name.Contains("finish"))
            {
                if (!fin)
                {
                    t   = Time.time;
                    fin = true;
                }
                if (r.GetComponent <Light>().range < range)
                {
                    r.GetComponent <Light>().range += Time.deltaTime * 2;
                    r.GetComponent <orbit>().SetOrb(r.GetComponent <Light>().range);
                }
                if (Time.time - t > cooldown && Vector3.Distance(r.transform.position, transform.position) < dist && r.GetComponent <Light>().range > range)
                {
                    fin = false;
                    GameObject[] objs = Resources.FindObjectsOfTypeAll <GameObject>();
                    foreach (GameObject obj in objs)
                    {
                        if (obj.name == "Finish" && obj.layer == 5)
                        {
                            gameObject.GetComponent <rotor>().SetTyp(-7);
                            GameObject.FindWithTag("level");
                            enabled = false;
                            obj.SetActive(true);
                            gameObject.GetComponent <rotor>().enabled         = false;
                            gameObject.GetComponent <TrailRenderer>().enabled = false;
                            stat st = GameObject.FindWithTag("stat").GetComponent <stat>();


                            if (st.GetLevel() <= LevelHandle.GetLoadedLevelId() && st.GetLevel() >= 0)
                            {
                                GameObject.FindWithTag("stat").GetComponent <stat>().PlusOne();
                                GameObject.FindWithTag("stat").GetComponent <stat>().SaveStats();
                            }
                            break;
                        }
                    }
                }
            }
            else
            {
                fin = false;
            }
        }
        else
        {
            fin = false;
        }
    }
Пример #5
0
        LevelHandle CheckNextLevel(GameObject target)
        {
#if UNITY_EDITOR
            if (!target)
            {
                Debug.LogError("no next level");
                return(null);
            }
#endif
            // retreave LevelHandle
            LevelHandle value = target.GetComponent <LevelHandle>();
#if UNITY_EDITOR
            // checking values
            if (value == null)
            {
                Debug.LogError("next level has no LevelHandler");
                return(null);
            }
            if (value.levelLength <= 0)
            {
                Debug.LogError("next level has no length");
                return(null);
            }
            if (value.nextLevels == null)
            {
                Debug.LogError("next level has no next levels");
                return(null);
            }
            // checking values one node further the line
            foreach (var it in value.nextLevels)
            {
                if (it == null)
                {
                    Debug.LogError("an element in the next level list is missing");
                    return(null);
                }
                if (!it.GetComponent <LevelHandle>())
                {
                    Debug.LogError("the level " + it.name + " in next levels has no level handler");
                    return(null);
                }
            }
#endif
            return(value);
        }