playMaker

Author Topic: How Can I add a script to a gameobject [SOLVED]  (Read 3046 times)

jrush64

  • Playmaker Newbie
  • *
  • Posts: 20
How Can I add a script to a gameobject [SOLVED]
« on: April 15, 2016, 08:20:39 AM »
Hi,

So I've tried using both the add a component and destroy component actions but neither seem to work.

I'm trying to add a script at runtime but it doesn't work.
« Last Edit: April 15, 2016, 10:30:44 AM by Alex Chouls »

Zeldag

  • Full Member
  • ***
  • Posts: 198
Re: How Can I add a script to a gameobject
« Reply #1 on: April 15, 2016, 08:57:27 AM »
Hi,

Would disabling a script and enabling it at runtime do the trick?

If so drag the script component from the gameobject's inspector into the action list of the state that should control the enabling.

When you drop the script component a small menu will appear, choose 'set property'.

In the set property action that has now appeared choose enable, then tick or untick the enable box as needed.

Good luck with it. I hope this helps you achieve what you are trying to do and let us know how it goes.

jrush64

  • Playmaker Newbie
  • *
  • Posts: 20
Re: How Can I add a script to a gameobject
« Reply #2 on: April 15, 2016, 09:03:06 AM »
Disabling won't do. Basically i'm having an animation issue with the third person controller I'm using.

I need to destroy the script for the animation to work properly then add it again when the animation is finished playing.

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4000
  • Official Playmaker Support
    • LinkedIn
Re: How Can I add a script to a gameobject
« Reply #3 on: April 15, 2016, 09:13:38 AM »
I just tested both actions here and they seem to be working fine.

Do you get an error in the console?
If the script is in a namespace, make sure you add the namespace to the script name. (e.g., MyNamespace.MyScriptName).

jrush64

  • Playmaker Newbie
  • *
  • Posts: 20
Re: How Can I add a script to a gameobject
« Reply #4 on: April 15, 2016, 09:18:55 AM »
I get this error.

"AddComponent : Can't add component: AnimatorMonitor"


Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4000
  • Official Playmaker Support
    • LinkedIn
Re: How Can I add a script to a gameobject
« Reply #5 on: April 15, 2016, 09:24:40 AM »
Is AnimatorMonitor in a namespace?
Can you post the source code for AnimatorMonitor?

jrush64

  • Playmaker Newbie
  • *
  • Posts: 20
Re: How Can I add a script to a gameobject
« Reply #6 on: April 15, 2016, 09:31:58 AM »
I'm not sure... Its from third person controller by opsive. I'm not sure if I can post the full source code but I can probably post the top part of the script.

Code: [Select]
using UnityEngine;
#if ENABLE_MULTIPLAYER
using UnityEngine.Networking;
#endif
using System.Collections.Generic;
using Opsive.ThirdPersonController.Abilities;

namespace Opsive.ThirdPersonController
{
    /// <summary>
    /// Added to the same GameObject as the Animator, the AnimationMonitor will control the trigger based Animator and translate mecanim events to the event system used by the Third Person Controller.
    /// </summary>
#if ENABLE_MULTIPLAYER
    public class AnimatorMonitor : NetworkBehaviour
#else
public class AnimatorMonitor : MonoBehaviour
#endif
    {

If that doesn't help, then I can send you the script by PM.

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4000
  • Official Playmaker Support
    • LinkedIn
Re: How Can I add a script to a gameobject
« Reply #7 on: April 15, 2016, 09:42:05 AM »
Use "Opsive.ThirdPersonController.AnimatorMonitor" as the name of the script.

Unfortunately the script popup doesn't include the namespace right now, so you have to add it manually.

jrush64

  • Playmaker Newbie
  • *
  • Posts: 20
Re: How Can I add a script to a gameobject
« Reply #8 on: April 15, 2016, 10:03:34 AM »
Ok that worked. Thank you.

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4000
  • Official Playmaker Support
    • LinkedIn
Re: How Can I add a script to a gameobject [SOLVED]
« Reply #9 on: April 17, 2016, 06:47:12 PM »
Cool. The next update improves the script selection menus so they include namespaces...