Forum rules - please read before posting.

[Solved] Enable and disable NPC script

edited October 2014 in Technical Q&A
Is there a way to enable the Npc script only when the player enter in a trigger? And disable when he exit?
I know how to set up a trigger but I don't know what action can do this... like an Object, Npc, Send message, Turn off and Turn on...

I have 5 npc and when they are all activated, in the profiler the voice "NPC.FixedUpdate" is at 86% and all slow down... when I uncheck the Npc script, all is working clear and smooth and become 0,1%! 
I also tryied to remove the capsule collider but become 75%...

Tx

Comments

  • You could either write a custom Action that disables/enables the NPC script of a given GameObject, or use the Object: Add or remove Action to physically delete/restore the entire GameObject.  Be sure to prefab the NPC, and place it in the Resources folder with a unique name - AC will need it to be there to be able to restore it when loading a saved game.
  • edited October 2014
    Ok guys, I discovered I'm really noob in programming... so, if some good boy can give me a hand with this script used to create a new action, i'll be really happy! Thinking @ChrisIceBox @Guran @hedgefield ... @othersWhoSpeakC#language... ^_^
    I would like to create an action that disable (or enable) the NPC.cs script from the game object called NPCMacho (with the prefab saved in resources folder). 
    I used the blank action template and inserted an instruction found on the unity forum, but it gives me errors and I don't know what's wrong:

    using UnityEngine;
    using System.Collections;

    #if UNITY_EDITOR
    using UnityEditor;

    namespace AC
    {

    [System.Serializable]
    public class ActionMachoDisable : Action
    {
    // Declare variables here
    override public float Run ()
    {
    GameObject.Find("NPCMacho").GetComponent(NPC).enabled=false;
    }
    }

    }

    Tx and sorry for my ignorance... 
    ~X(
  • edited October 2014
    Have you read the tutorials on writing Actions?  You could extend this to let you choose which NPC to affect, as well as a "enable / disable" box.

    Either way, you're nearly there!

    GameObject.Find ("NPCMacho").GetComponent ().enabled = false;
  • Now works great, tx man!

    And yes, I read the tut on custom actions and i already created one for enable and one for disable the speech skip.
    My knowledgment and understanding can make me do those single action... but it's enought, tx! ^_^
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.