Why is the Text box flashing I have followed countless tutorials and no matter what it happens?
using JetBrains.Annotations;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq.Expressions;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.UIElements;
using UnityEngine.XR;
using System.Diagnostics;
using Debug = UnityEngine.Debug;
public static class ScriptedEvents
{
public static string Event;
public static int Timer;
}
public class Scene_Management : MonoBehaviour
{
public Rigidbody pRb;
public Light Sun;
public Light Flashlight;
public bool doneLine = false;
public float subTitleSpeed = 1;
public List<string> eventsDone = new List<string>();
//public Text subtitles;
float LightsTimer(float seconds)
{
return Mathf.RoundToInt(seconds - Time.deltaTime);
}
IEnumerator LightFlicker(Light light, int t,int interval)
{
if(t - (1 * Time.time) >= 0)
{
light.enabled = !light.enabled;
yield return new WaitForSeconds(interval);
}
}
void TriggerSunlightFade(int t)
{
if (LightsTimer(t) > 0)
{
Sun.intensity = Mathf.Lerp(Sun.intensity, Mathf.Max(-(Sun.intensity / LightsTimer(t)), 0), Time.deltaTime);
}
}
void TriggerSunlightBrighten(int t)
{
Sun.intensity = Mathf.Lerp(Sun.intensity, Mathf.Max((Sun.intensity / LightsTimer(t)), 0.8f), Time.deltaTime);
}
IEnumerator StartGame(Text sub)
{
string[] displayText = new string[] { "Welcome to Axial hope you enjoy you're time here.",
"Move the mouse the left or right to tilt the world, Left click to bounce and right click to stop.",
"Tilt the phone left and right to tilt the world, Single tap to bounce and use both your thumbs to stop." };
sub.text = displayText[0];
yield return new WaitForSeconds(4);
sub.enabled = false;
eventsDone.Add("StartGame");
yield return null;
}
IEnumerator Well(Text sub)
{
String[] displayText = new string[] { "Oh it's dark down here here let me turn on the flashlight.",
"Oh it's out of batteries hang on be right back", "(Footsteps)", "(Silence)", "(Running Footsteps)",
"OK I am back (Panting) ... *(Click)* ... ok there we go.", "Oh forgot to unfreeze you."};
TriggerSunlightFade(3);
if(!PlayerPrefs.HasKey("Well"))
{
sub.enabled = true;
sub.text = displayText[0];
//Flashlight.enabled = !Flashlight.enabled;
yield return new WaitForSeconds(3);
PlayerPrefs.SetInt("Well",0);
}
else
{
if(PlayerPrefs.GetInt("Well") == 0)
{
sub.text = displayText[1];
Flashlight.enabled = false;
yield return new WaitForSeconds(3);
}
}
}
// Start is called before the first frame update
void Start()
{
PlayerPrefs.DeleteAll();
gameObject.SetActive(true);
}
// Update is called once per frame
void FixedUpdate()
{
Text sub = GetComponent<Text>();
GameObject player = GameObject.Find("Player");
Transform playerTransform = player.transform;
Vector3 playerPos = player.transform.position;
if(!eventsDone.Contains("StartGame"))
{
StartCoroutine(StartGame(sub));
}
else
{
if (playerPos.y < -0.5f)
{
StartCoroutine(Well(sub));
}
}
}
}
I can run the first line no problem but after that always flashes no matter what I try. Like I said been through every tutorial followed exactly and the same issue tried own things still the same problem.
Answer by cofcof · Sep 16, 2020 at 06:53 PM
Figured it out nevermind IEnumerator StartGame(Text sub) { string[] displayText = new string[] { "Welcome to Axial hope you enjoy you're time here.", "Move the mouse the left or right to tilt the world, Left click to bounce and right click to stop.", "Tilt the phone left and right to tilt the world, Single tap to bounce and use both your thumbs to stop." }; if(!PlayerPrefs.HasKey("StartGame")) { sub.text = displayText[0]; yield return new WaitForSeconds(4); PlayerPrefs.SetInt("StartGame", 0); } if(PlayerPrefs.GetInt("StartGame") == 0) { sub.text = displayText[1]; yield return new WaitForSeconds(5); PlayerPrefs.SetInt("StartGame", 1); sub.enabled = false; } }
Your answer
Follow this Question
Related Questions
How to create an if statement for each element within a list C# 2 Answers
Unity 5.1 GUI mask disappears in Android build 0 Answers
Adjusting content display. 0 Answers
Unity Dropdown Menu Not Closing 1 Answer