Question about triggering an event (Extremely Novice to Programming)
I have a wee game that I've got working, as far as the interactivity goes. But, in my lack of foresight, I need to add a couple instructional panels.
What I have is this: I have an animator that controls the OPEN and CLOSED states for 3 different UI panels. When the scene is launched, the animator slides the first UI panel in from the left. This animator is controlled by a ScreenManager.cs script attached to an Empty Game Object, I've called ScreenManager.
I have another script called ShopliftingInteractivity.cs that dictates what happens when the user interacts with the different elements of the UI.
What I want is this: At the point that the animator has shown the first panel, but before the user stars tapping things all willy-nilly, I'd like to Set.Active an overlay panel that serves as an instruction screen. I would like to call this Instructional screen from my ShopliftingInteractivity.cs script, to keep the ScreenManager.cs only dealing with showing the UI panels.
For the life of me, I cannot figure out the magical incantation that will allow me to do this.
I've tried:
public Animator AmateurCrimeboard;
public void ShowInstructionPanelOne ()
{
if (Animator AmateurCrimeboard.isInitialized)
{
InstructionPanelOne.SetActive (true);
}
}
I've also tried:
public void ShowInstructionPanelOne ()
{
if (Animator AmateurCrimeboard.isActiveAndEnabled)
{
InstructionPanelOne.SetActive (true);
}
}
I've also tried:
public void ShowInstructionPanelOne ()
{
if (AmateurCrimeboard==true)
{
InstructionPanelOne.SetActive (true);
}
}
The thing is, I don't quite understand all the language in the manual, so I don't really know what it is that I'm looking for. I am also not a programmer, I am a graphic designer who is really trying to learn. I believe I'm close, but I'm not using the correct syntax.
I would appreciate help from someone more knowledgeable than myself. Thank you kindly, in advance.
with animation events: http://docs.unity3d.com/$$anonymous$$anual/animeditor-AnimationEvents.html
you can call methods at a specific time-position in your event. e.g. at the end of a animation
Answer by cre8or · Apr 22, 2016 at 03:22 PM
Okay, I believe I have solved my problem. It may not be the most eloquent solution, but it does seem to work:
// waits for two seconds before calling the ShowInstructionPanelOne function
void Awake()
{
Invoke ("ShowInstructionPanelOne", 2);
}
//Shows the Instruction Panel only if the AmateurUI is active in the scene
void ShowInstructionPanelOne()
{
if (AmateurUI.activeSelf)
InstructionPanelOne.SetActive (true);
}
The Amateur UI is on a canvas that also contains two other UIs and is controlled by an animator to slide each in/out based on user interaction. I wanted the first instruction screen to be an overlay on top of the UIs, so the instruction screens (3 of them) are on another Canvas, with the order set to 1. After a delay of 2 seconds, the InstructionPanelOne is displayed onto of the AmateurUI with the instructions. Once the user had read the instructions, they can dismiss this panel and continue on.
Like I said, it may not be beautiful, but it does work.