Thank you to anyone reading this, I’m having great difficulty figuring out why all of a sudden my code isn’t working. To start, I’m not the best at programming and so I apologize if my script looks very ugly to those that are experts in understanding and reading code.
So I intially had it working, or so I thought. The video below shows it to be working, but I noticed later that the executable I made around that time showed it wasn’t.
Below this text is my most recent video and it shows that the first UI is displaying because I have it programmed in void start() to equal true. The code works intially beause of that, in which the player can’t move until after they press ‘0’. My triggers do seem to be working because when the player walks towards the moveable box, I have a debug line that appears in my Console that is showing that player is near the box.
Below this text I will post my code as well as a screenshot showing that I have my InstructionsUI placed within the Canvas object of the Heirarchy and the order of the texts displaying within the Inspector. Also in the screenshot it will show that I do have my C# script placed inside of my FPS Standard Assets because I learned previously that was the only way my FirstPersonController script would have access to my script for InstructionsUI.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.Characters.FirstPerson;
public class InstructionsUI : MonoBehaviour
{
public GameObject boxForText;
private bool makeBoxAppear;
private bool bufferBetweenTexts;
public static bool allowToWalk;
// public static float speedOfWalk;
public GameObject introText1;
public GameObject introBox2;
public GameObject introPickaxe3;
public GameObject introCrystals4;
public GameObject introMachine5;
public GameObject introRunning6;
public GameObject introSpace7;
public GameObject warning7;
private bool nearTheBox;
private bool nearThePickaxe;
private bool nearCrystals;
private bool isNearMachine;
private bool nearSpace;
private bool playerCanRun;
private bool firstInstruct;
private bool secondInstruct;
private bool thirdInstruct;
private bool fourthInstruct;
private bool fifthInstruct;
private bool sixthInstruct;
private bool seventhInstruct;
// Start is called before the first frame update
void Start()
{
boxForText.SetActive(true);
makeBoxAppear = true;
//bufferBetweenTexts = false;
allowToWalk = false;
//speedOfWalk = 0f;
//Boolean values in order of how the instructions are given to player
firstInstruct = false;
secondInstruct = false;
thirdInstruct = false;
fourthInstruct = false;
fifthInstruct = false;
sixthInstruct = false;
seventhInstruct = false;
//Game objects that hold the text and are only true based on boolean values above
introText1.SetActive(true);
introBox2.SetActive(false);
introPickaxe3.SetActive(false);
introCrystals4.SetActive(false);
introMachine5.SetActive(false);
introRunning6.SetActive(false);
introSpace7.SetActive(false);
warning7.SetActive(false);
}
// Update is called once per frame
void Update()
{
nearTheBox = FirstPersonController.nearBox;
//nearThePickaxe = FirstPersonController.hasPickaxe;
nearThePickaxe = pickaxeHold.allowedToSwing;
nearCrystals = FirstPersonController.nearHarvestCrystals;
isNearMachine = FirstPersonController.nearMachine;
nearSpace = FirstPersonController.isNearSpace;
playerCanRun = FirstPersonController.runInstructions;
// allowToWalk = FirstPersonController.playerCanWalk;
//speedOfWalk = FirstPersonController.m
//Make intro go away
if (Input.GetKeyDown(KeyCode.Alpha0) && firstInstruct == false)
{
boxForText.SetActive(false);
introText1.SetActive(false);
firstInstruct = true;
makeBoxAppear = false;
allowToWalk = true;
//speedOfWalk = 6f;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Bring up second introduction when player is near the box
if (firstInstruct == true && nearTheBox == true && makeBoxAppear == false && secondInstruct == false)
{
boxForText.SetActive(true);
introBox2.SetActive(true);
makeBoxAppear = true;
allowToWalk = false;
//speedOfWalk = 0f;
}
//Player presses 0 to make second text to disappear
if (Input.GetKeyDown(KeyCode.Alpha0) && secondInstruct == false && makeBoxAppear == true)
{
makeBoxAppear = false;
secondInstruct = true;
boxForText.SetActive(false);
introBox2.SetActive(false);
allowToWalk = true;
//speedOfWalk = 6f;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Bring up third introduction when player collides with pickaxe
if (secondInstruct == true && nearThePickaxe == true && makeBoxAppear == false && thirdInstruct == false)
{
boxForText.SetActive(true);
introPickaxe3.SetActive(true);
makeBoxAppear = true;
allowToWalk = false;
// speedOfWalk = 0f;
}
//Player presses 0 to make third text to disappear
if (Input.GetKeyDown(KeyCode.Alpha0) && thirdInstruct == false && makeBoxAppear == true)
{
makeBoxAppear = false;
thirdInstruct = true;
boxForText.SetActive(false);
introPickaxe3.SetActive(false);
allowToWalk = true;
//speedOfWalk = 6f;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Bring up fourth introduction when player is near crystals
if (thirdInstruct == true && nearCrystals == true && makeBoxAppear == false && fourthInstruct == false)
{
boxForText.SetActive(true);
introCrystals4.SetActive(true);
makeBoxAppear = true;
allowToWalk = false;
}
//Player presses 0 to make fourth text to disappear
if (Input.GetKeyDown(KeyCode.Alpha0) && fourthInstruct == false && makeBoxAppear == true)
{
makeBoxAppear = false;
fourthInstruct = true;
boxForText.SetActive(false);
introCrystals4.SetActive(false);
allowToWalk = true;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Bring up fifth introduction when player is near crystals
if (fourthInstruct == true && isNearMachine == true && makeBoxAppear == false && fifthInstruct == false)
{
boxForText.SetActive(true);
introMachine5.SetActive(true);
makeBoxAppear = true;
allowToWalk = false;
}
//Player presses 0 to make fifth text to disappear
if (Input.GetKeyDown(KeyCode.Alpha0) && fifthInstruct == false && makeBoxAppear == true)
{
makeBoxAppear = false;
fifthInstruct = true;
boxForText.SetActive(false);
introMachine5.SetActive(false);
allowToWalk = true;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Bring up sixth introduction when player is near running
if (fifthInstruct == true && playerCanRun == true && makeBoxAppear == false && sixthInstruct == false)
{
boxForText.SetActive(true);
introRunning6.SetActive(true);
makeBoxAppear = true;
allowToWalk = false;
}
//Player presses 0 to make sixth text to disappear
if (Input.GetKeyDown(KeyCode.Alpha0) && sixthInstruct == false && makeBoxAppear == true)
{
makeBoxAppear = false;
sixthInstruct = true;
boxForText.SetActive(false);
introRunning6.SetActive(false);
allowToWalk = true;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Bring up seventh introduction when player is near space
if (sixthInstruct == true && nearSpace == true && makeBoxAppear == false && seventhInstruct == false)
{
boxForText.SetActive(true);
introSpace7.SetActive(true);
warning7.SetActive(true);
makeBoxAppear = true;
allowToWalk = false;
}
//Player presses 0 to make seventh text to disappear
if (Input.GetKeyDown(KeyCode.Alpha0) && seventhInstruct == false && makeBoxAppear == true)
{
makeBoxAppear = false;
seventhInstruct = true;
boxForText.SetActive(false);
introSpace7.SetActive(false);
warning7.SetActive(false);
allowToWalk = true;
}
}
}
Here is the screenshot as I mention above showing the Heirarchy, my Project files within my Standard Assets of my FPS Controller and the Inspector showing how the objects within the Heirarchy are all hooked up in order of their number.
Thank you so much for your time in helping me with this. Any help is very appreciated.