playMaker

Author Topic: access variable on collision  (Read 1576 times)

zombie

  • Playmaker Newbie
  • *
  • Posts: 9
access variable on collision
« on: March 07, 2017, 01:34:58 AM »
How do I access a variable on a script attached to an object that collides with the object the FSM is attached to?

So if I have a colliding object with a class called PlayerInformation, and I want to access the public variable hasKey, I would do something like the following in C#, but I can't even figure out where to begin with Playmaker.

Code: [Select]
PlayerInformation info = collidingObject.gameObject.GetComponent<PlayerInformation>();
bool hasKey = info.hasKey;
« Last Edit: March 07, 2017, 02:07:31 AM by zombie »

tcmeric

  • Beta Group
  • Hero Member
  • *
  • Posts: 768
Re: access variable on collision
« Reply #1 on: March 08, 2017, 11:22:10 PM »
If I understand this properly, here is a start (maybe not the total solution).

1.

You need a trigger event, set to on enter. It has a field called "store collider". This is the gameobject that you collided with. Create a variable, and store the gameobject you collided with.
Example name: GameObjectVar

This allows you to access the correct game objects script.

2. Create another variable (before hand). Object type. In the variable browser, make sure to set the correct object type. You should find a list of scripts to access when setting the object type. Drill down to what you need. Save.
Example name: ObjectVar

3. Next, use the action "get component"., which can use the gameobject variable you saved, and get the right component into the object variable you pre-created.
Example: GameObjectVar to ObjectVar

4. Use get property. It allows you to choose the "object" variable you saved, and then pull out a variable from it, and save it in a playmaker variable.
Example: ObjectVar to PlaymakerVar

5. Step 5, name first born after me. Either Eric or Erika will be acceptable (depending on the sex).