Forum rules - please read before posting.

[SOLVED] how to connect a game object to variables?

edited July 2014 in Technical Q&A
Can someone please tell me excatly; how to connect variable and gameobjects?

Imagine; our Mission is firing the fireplace

After we found some objects and combine each other,  we can finally heat up our firing place.

Now the mission is done. 

So I create a local variable "FireInTheHole", type "boolean" I marked it "false" as initial value (what is difference between local and global?local is for scene, global is for game?)

And I create a cutscene, and it checks variables

source:"local", compare with "entered value" 

"FireInTheHole", "equal to", "true", lets start action.

Now everything is perfect.

I have particle system for fire. It is invisible at the beginning, it becomes visible when we do correct moves.

So how we connect this gameobject visibility to this "FireInTheHole" variable?

Comments

  • Local variables are specific to the scene in which they're created - global variables can be accessed in any scene.

    Attach a ParticleSwitch script to your particle system, and when you set your variable to true, use the Object: Send message Action to pass "Turn On" to the system - this will turn it on.

    Since the state of particle systems are not saved, you will have to create an "On load" cutscene that sets the state manually. Simply check the variable as you have done before, and then either send "Turn On" or "Turn Off" as appropriate.
  • Thank you Chris, but I couldnt understand, how I make my variable true? This is my problem. How can i connect my variable to my particle system without write any script? 

    I attach particle switch script to my particle system. Then I dont know what should I do

    Should I add local variable script to particle system? Then after I create two size, one for "true" one for "false"? This part I couldnt understand.

    Your system is great, I dont know so much about unity, I am 3d artist, but I can easily create nearly everything what I need. Only thing is this variables, this is my second question about variables, because there is not so much documentation or tutorials about variables...


  • No problem - don't add any other scripts to your particle system, certainly not the LocalVariables script!

    Inside the Variables Manager (in the main Game Editor window), look for the Local Variables section and click Create new Local Variable.  Be sure to do this when in the same scene as your particle system, as this variable will live in the scene in which you click this button.

    Leave the new local variable's type as a Boolean (this is like an on/off switch), and set it's label to something like "Fire is on".  If your game starts with the fire off, leave the variable's Initial value as False.

    Then, you can use the Variable: Set Action to change this value in-game.  For example, when your puzzle is solved, call this Action, setting the Source to Local, selecting your local variable, and setting it to True.  In a separate Cutscene, create a Variable: Check Action to query the value of this variable.  When the value is True (i.e. the fire is on, use the Object: Send message Action to turn on the particle system in the way I described above).  When False, turn it off with by doing the same but passing the message "Turn Off".  You can use the ActionList Editor window to better visualise this chain of Actions, since you can wire them up in a WYSIWYG way.

    Then, call this Cutscene whenever you want your game to decide whether or not the particles should be on: you ought to call it whenever the local variable's value is changed, and when your game loads this scene.  You can call a Cutscene from any other by using the Engine: Run ActionList Action.

    This video tutorial is somewhat out of date so far as the look of the interface goes, but the principles are the same.
  • Thank you Chris, I appreciated your help. it works very well... 
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.