Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Goatcheesecough · Oct 09, 2015 at 03:15 PM · javascriptscript.disabling

Need help completely disabling a script

 #pragma strict
 
 var talkLines:String[];
 var talkTextGUI:UnityEngine.UI.Text;
 var textscrollSpeed:int;
 
 private var talking:boolean;
 private var textIsScrolling:boolean;
 private var playerScript:UnityStandardAssets.Characters.FirstPerson.FirstPersonController;
 private var currentLine:int;
 
 function OnTriggerEnter(col:Collider){
     if(col.tag == "Player"){
     playerScript = col.GetComponent(UnityStandardAssets.Characters.FirstPerson.FirstPersonController);
      Debug.Log(playerScript);
      talking = true;
      currentLine = 0;
      //talkTextGUI.text = talkLines[currentLine]; //STATIC
      startScrolling();
      playerScript.enabled = false;     
      
     }
 }
 
 function Update () {
     if(talking){
         if(Input.GetButtonDown("Npcmt")){
             if(textIsScrolling){
             //display full line
             talkTextGUI.text = talkLines[currentLine];
             textIsScrolling = false;
             }
             else{
                 //display next line
                 if(currentLine < talkLines.Length - 1){
                 currentLine++;
                 //talkTextGUI.text = talkLines[currentLine]; //STATIC
                 startScrolling();
                 }
                 else{
                     currentLine = 0;
                     talkTextGUI.text = "";
                     talking = false;
                     playerScript.enabled = true;
 
 }
 }
 }
 }
 }
 
 function startScrolling(){
 textIsScrolling = true;
 var startLine:int = currentLine;
 var displayText:String = "";
 
 for(var i:int = 0; i < talkLines[currentLine].Length; i++){
   if(textIsScrolling && currentLine == startLine){
 displayText += talkLines[currentLine][i];
 talkTextGUI.text = displayText;
 yield WaitForSeconds(1/ textscrollSpeed);
 
 }
 }
 }

Above is my NPC talking script in Unity.

 #pragma strict
 
 var script : NPCscript;
 
 function Start() {
 script = GetComponent(NPCscript);
 script.enabled = false;
 }

Above is my disabling script for the NPC script. The problem is that when I disable the script it doesn't fully work and it shows the first line of dialogue and you can't continue the dialogue. I want all the dialouge to be fully disabled and not to work. The variable talking and the variable textIsScrolling become true when the script is disabled when I talk to the NPC and I think that that is the problem.

Thanks, ~Jordan

P.S Both of these scripts are in JS.

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image meat5000 ♦ · Oct 09, 2015 at 03:34 PM 1
Share

Disabling a script simply stops the running of $$anonymous$$onoBehaviours (Update etc) but anything else will still run.

If you truly want to disable the script, place it on an object and disable the object.

avatar image Owen-Reynolds · Oct 09, 2015 at 05:42 PM 0
Share

The other common hacky way is to add something else like your talking variable, say turnedOff, and check for that at the start of OnTriggerEnter.

avatar image hexagonius Owen-Reynolds · Oct 09, 2015 at 08:29 PM 0
Share

wasn't that in one of the release notes that collision and trigger callbacks are not called if the script is disabled?

avatar image Owen-Reynolds hexagonius · Oct 09, 2015 at 08:55 PM 0
Share

$$anonymous$$aybe, don't know. But the current docs say OnCollision is intentionally called on a disabled script. Bottom of 2nd para: http://docs.unity3d.com/ScriptReference/$$anonymous$$onoBehaviour.OnCollisionEnter.html

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Goatcheesecough · Oct 10, 2015 at 04:01 PM

Thanks everyone but I just ended up using meat5000's trick.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Statement · Oct 09, 2015 at 10:51 PM

Try adding this guard to OnTriggerEnter:

 if (!enabled)
     return;

IIRC, physics callbacks are still sent even though the script is disabled.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Flip over car after tips over? 1 Answer

I'm trying to display my ammo; not working 2 Answers

Problem with simple JavaScript, No appropriate version of 'UnityEngine.Object.Instantiate' for the argument list '(UnityEngine.GameObject, UnityEngine.Vector3)' was found. 1 Answer

Realistic reloading system 1 Answer

Setting Scroll View Width GUILayout 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges