playMaker

Author Topic: [SOLVED] Activate Game Object Based on string  (Read 1053 times)

swiiiftz

  • Playmaker Newbie
  • *
  • Posts: 3
[SOLVED] Activate Game Object Based on string
« on: August 27, 2021, 04:21:47 PM »
First things first im pretty much brand new to playmaker and pretty new to Unity and game dev in general so please bare with me.

I started of by following the FPS video tutorials. Now im messing around with some of its features and managed to do some things on my own like fixing the crosshair color while looking at the ground/walls, implemented a new way of determinating the color so i can display more than 2 colors etc... now to my problem.
I wanted to add a beam that is displayed while holding a Object. I through together aquick particle system that is enabled at the "MoveToHolder" state and deactivated after you throw or drop an Object. Feels like I took the "wrong" approach but it works. Now set a string in the Reticle fsm that changes depending on the crosshair color.
Now my question is how do I setup a state that activates a Gameobject depending on a string?
I dont know if anyone can follow my explanation but any help is much appreciated.
« Last Edit: August 28, 2021, 01:52:41 PM by swiiiftz »

ToxicFrog

  • Beta Group
  • Full Member
  • *
  • Posts: 139
Re: Activate Game Object Based on string
« Reply #1 on: August 28, 2021, 09:14:33 AM »
Someone may reply with better advice, but here's what I've got:

A. The easiest way (which you should not do):
1. 'Find Game Object' (by name and optionally by tag also). Store as 'ObjectToActivate'
2. Activate 'ObjectToActivate'

You should not use 'Find Game Object', because it is not efficient. It will search the entire scene until it finds the object, which can hurt performance


B. The better way:
1. Add ArrayMaker to your project
2. Store the object(s) to be activated in the array
3. 'Array List Contains' by name and optionally by tag also). If True, Store as 'ObjectToActivate'.
4. 'Activate 'ObjectToActivate'

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7618
    • jinxtergames
Re: Activate Game Object Based on string
« Reply #2 on: August 28, 2021, 09:23:19 AM »
Hi.
You can use a 'String Changed' and a 'String Switch' and set as a loop

When string is changed, then do string switch and set what you need.
Them loop back to 'String Changed'.

ToxicFrog

  • Beta Group
  • Full Member
  • *
  • Posts: 139
Re: Activate Game Object Based on string
« Reply #3 on: August 28, 2021, 09:29:51 AM »
@djaydino

I'm doing something completely different from this post, but your advice is exactly what I need for what I'm working on :)

swiiiftz

  • Playmaker Newbie
  • *
  • Posts: 3
Re: Activate Game Object Based on string
« Reply #4 on: August 28, 2021, 01:51:03 PM »
tried the Array thing but wasnt really for me. Tnaks for the detailed answer anyways @ToxicFrog

looked a bit more into the available actions and ended up doing pretty much exactly what @djaydino suggested. Thanks for the confirmation tho.