Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: jrush64 on April 15, 2016, 08:20:39 AM

Title: How Can I add a script to a gameobject [SOLVED]
Post by: jrush64 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.
Title: Re: How Can I add a script to a gameobject
Post by: Zeldag 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.
Title: Re: How Can I add a script to a gameobject
Post by: jrush64 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.
Title: Re: How Can I add a script to a gameobject
Post by: Alex Chouls 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).
Title: Re: How Can I add a script to a gameobject
Post by: jrush64 on April 15, 2016, 09:18:55 AM
I get this error.

"AddComponent : Can't add component: AnimatorMonitor"

Title: Re: How Can I add a script to a gameobject
Post by: Alex Chouls on April 15, 2016, 09:24:40 AM
Is AnimatorMonitor in a namespace?
Can you post the source code for AnimatorMonitor?
Title: Re: How Can I add a script to a gameobject
Post by: jrush64 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.
Title: Re: How Can I add a script to a gameobject
Post by: Alex Chouls 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.
Title: Re: How Can I add a script to a gameobject
Post by: jrush64 on April 15, 2016, 10:03:34 AM
Ok that worked. Thank you.
Title: Re: How Can I add a script to a gameobject [SOLVED]
Post by: Alex Chouls on April 17, 2016, 06:47:12 PM
Cool. The next update improves the script selection menus so they include namespaces...