Question by
CNSoftware · Feb 27, 2018 at 02:53 PM ·
c#scripting problemscripting beginnerlevel loadlevel select
level manger and starting scene will not work together
i am trying to make a boot up scene for my game and with a float to transition to the main menu scene but the 2 scripts interfere with one a another i new to c# so i don`t how how to fix the problem if anyone can help it will be greatly appreciated ( i have stared* the problem area )
Next scene script
using System.Collections;
using UnityEngine;
using UnityEngine.Video;
using UnityEngine.SceneManagement;
public class nextscene: MonoBehaviour
{
** public float delay = 23;
void Start()
{
StartCoroutine(LoadLevelAfterDelay(delay));
}
IEnumerator LoadLevelAfterDelay(float delay)
{
yield return new WaitForSeconds(delay);
SceneManager.LoadScene("MainMenu");
}
}
my Level Select Manager script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LevelSelectManager : MonoBehaviour {
public string[] levelTags;
public GameObject[] locks;
public bool[] levelUnLocked;
public int positionSelector;
public float distanceBelowLock;
public string[] levelName;
public float moveSpeed;
private bool isPressed;
void Start(){
for(int i = 0; i < levelTags.Length; i++)
{
** if (PlayerPrefs.GetInt (levelTags [i]) == null) {
levelUnLocked [i] = false;
} else if (PlayerPrefs.GetInt (levelTags [i]) == 0) {
levelUnLocked [i] = false;
} else {
levelUnLocked [i] = true;
}
if (levelUnLocked [i]) {
locks [i].SetActive (false);
}
}
transform.position = locks [positionSelector].transform.position + new Vector3 (0, distanceBelowLock, 0);
}
void Update(){
if (!isPressed) {
if (Input.GetAxis ("Horizontal") > 3.0f) {
positionSelector += 1;
isPressed = true;
}
if (Input.GetAxis ("Horizontal") < -3.0f) {
positionSelector -= 1;
isPressed = true;
}
if (positionSelector >= levelTags.Length) {
positionSelector = levelTags.Length;
}
if (positionSelector <= levelTags.Length) {
positionSelector = levelTags.Length;
}
}
if (isPressed) {
if (Input.GetAxis ("Horizontal") < 3f && Input.GetAxis ("Horizontal") > -3f) {
isPressed = false;
}
}
transform.position = Vector3.MoveTowards (transform.position, locks [positionSelector].transform.position + new Vector3 (0, distanceBelowLock, 0), moveSpeed * Time.deltaTime);
}
}
Comment