playMaker

Author Topic: need help with a simple trigger event + c# script  (Read 1591 times)

peaks

  • Playmaker Newbie
  • *
  • Posts: 27
need help with a simple trigger event + c# script
« on: May 03, 2017, 03:38:45 AM »
Hi folks!

I need your help with a simple trigger event which should fire off a line of code, unfortunately my c# skills are "limited aka non existing.." to combine it with my fsm.

Setup: I have a box collider set to trigger, and a simple fsm which fires off a state when my player enter the trigger box.

now the tricky part: I would like to trigger the "cursor.ChangeLength(cursor.rope.Length - 1f * Time.deltaTime);" of a c#-code, when my player entered the trigger, instead of using the keyboard key for firing it off.

Could you guys help me out?

Code: [Select]
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Obi;

public class CursorController : MonoBehaviour {

ObiRopeCursor cursor;



// Use this for initialization
void Start () {
cursor = GetComponentInChildren<ObiRopeCursor>();
}

// Update is called once per frame
void Update () {
if (Input.GetKey(KeyCode.W)){
cursor.ChangeLength(cursor.rope.Length - 1f * Time.deltaTime);
}

if (Input.GetKey(KeyCode.S)){
cursor.ChangeLength(cursor.rope.Length + 1f * Time.deltaTime);
}

}
}


« Last Edit: May 03, 2017, 06:50:43 AM by peaks »

Deek

  • Full Member
  • ***
  • Posts: 133
Re: need help with a simple trigger event + c# script
« Reply #1 on: May 03, 2017, 05:26:45 PM »
The easiest way in your scenario is shown in the screenshots. You attach your script to any GameObject in the hirarchy (preferably the one you're using it on), disable it and drag it to the right side of the Playmaker Editor in the Action after the trigger event. Then you choose 'Set Property'. Under 'Property' you choose 'Enabled' and tick the checkbox to enable the script.

Alternatively under 'Set Property' you could choose 'Script Control' > 'Call Method' if you had specified a Method in your script. Then you could fire that Method. But since you do it in OnUpdate() wich fires automatically every frame as long as the script is active in the scene, my first advice should suffice.