playMaker

Author Topic: triggers and the different events[SOLVED]  (Read 3004 times)

Sjones

  • Full Member
  • ***
  • Posts: 203
triggers and the different events[SOLVED]
« on: April 09, 2013, 11:59:00 PM »
I am back to the collision (been using the old PM 1.4 for testing)

I had some issues way back when 1.4.4 came out, I am not entirely sure I have resolved them 100% but I am making progress.

one problem I am having with a custom script that was working before was a script listening to all 3 types of trigger events (edited the triggerEvent)

Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2011. All rights reserved.

using System;
using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Physics)]
[Tooltip("Detect collisions with objects that have RigidBody components. \nNOTE: The system events, TRIGGER ENTER, TRIGGER STAY, and TRIGGER EXIT are sent when any object collides with the trigger. Use this action to filter collisions by Tag.")]
public class TriggerCount : FsmStateAction
{
// public TriggerType trigger;
[UIHint(UIHint.Tag)]
public FsmString collideTag;
// public FsmEvent sendEvent;
public FsmInt collideCount;
// public FsmInt maxCollide;
public FsmBool collidedBool;
public bool everyFrame;

public override void Reset()
{
// trigger = TriggerType.OnTriggerEnter;
collideTag = "Untagged";
// sendEvent = null;
collideCount = null;
collidedBool = null;
everyFrame = false;
}


public override void OnEnter()
{
if (!everyFrame)
Finish();
}

public override void DoTriggerEnter(Collider other)
{
if (other.gameObject.tag == collideTag.Value)
{
collideCount.Value = collideCount.Value + 1;
}
}

public override void DoTriggerExit(Collider other)
{
if (other.gameObject.tag == collideTag.Value)
{
collideCount.Value = collideCount.Value - 1;
}
}

public override void OnUpdate()
{
if (collideCount.Value == 0 )
{
collidedBool.Value = false;
}
else
{
collidedBool.Value = true;
}
}

// public override string ErrorCheck()
// {
// return ActionHelpers.CheckOwnerPhysicsSetup(Owner);
// }


}
}

the issue is with the update, from what I gather, it only can do one type per script?
Code: [Select]
public override void Awake()
{
switch (trigger)
{
case TriggerType.OnTriggerEnter:
Fsm.HandleTriggerEnter = true;
break;
case TriggerType.OnTriggerStay:
Fsm.HandleTriggerStay = true;
break;
case TriggerType.OnTriggerExit:
Fsm.HandleTriggerExit = true;
break;
}
}

my version, based on the old system only records enters now and not exits (I dont test for stays) is this the case or am I wrong, is there a fix? or do I have to have 2 separate actions, if so is there a chance that it could miss an event if 2 actions are used?
« Last Edit: April 11, 2013, 02:24:19 AM by jeanfabre »

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3998
  • Official Playmaker Support
    • LinkedIn
Re: triggers and the different events
« Reply #1 on: April 10, 2013, 03:27:51 AM »
You can set more than one condition to true.

E.g., set both HandleTriggerEnter and HandleTriggerExit to true.

Sjones

  • Full Member
  • ***
  • Posts: 203
Re: triggers and the different events
« Reply #2 on: April 10, 2013, 11:10:10 AM »
I tried that and it still didn't seem to work, will take another go and see if I done something wrong

Sjones

  • Full Member
  • ***
  • Posts: 203
Re: triggers and the different events
« Reply #3 on: April 10, 2013, 11:38:23 AM »
I just re-tried this, it does work! :D

my guess is the last attempt I made it was editing the script while it the game was running, and the awake was already called? and didn't add the correct stuff etc.