Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 ThomasMarsh · Jan 04, 2015 at 04:42 AM · javascriptprefabfailure

Random Script Failure

I have noticed multiple times that while I am editing other parts of my level in Unity, I will test it out and find out that the scripts in the doors no longer seem to be active/working. The only way I have found to fix this is to delete the door and replace it from the prefab. Attempting to revert to the prefab does not work. I am editing objects that are seemingly unrelated to the doors themselves. Does anyone know why this is happening and/or how to fix it? It is currently quite a pain to replace the doors every few minutes.

Here is the script if it helps:

 #pragma strict
 
 function OnTriggerEnter (obj : Collider) {
     var thedoor = gameObject.FindWithTag("SF_Door");
     thedoor.animation.Play("open");
 }
 
 function OnTriggerExit (obj : Collider) {
     var thedoor = gameObject.FindWithTag("SF_Door");
     thedoor.animation.Play("close");
 }
Comment
Add comment · Show 2
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 getyour411 · Jan 04, 2015 at 07:45 AM 0
Share

I don't work in JS but "obj" might be a reserved word? Also, you are not actually using the variable, ala

 if(obj.name == "Door")

Is "gameObject" a typo here, i.e. are you using GameObject.FindWithTag (uppercase G)

avatar image ThomasMarsh · Jan 04, 2015 at 04:01 PM 0
Share

It is searching for the object SF_Door within the children of the gameObject.

1 Reply

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

Answer by tanoshimi · Jan 04, 2015 at 08:39 AM

If this script is attached to the doors (which also have a trigger collider attached), and you want them to play the open/close animation whenever a collider enters that trigger, you should just be able to do:

 #pragma strict
 function OnTriggerEnter (obj : Collider) {
   animation.Play("open");
 }
 function OnTriggerExit (obj : Collider) {
   animation.Play("close");
 }
Comment
Add comment · Show 2 · 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 ThomasMarsh · Jan 04, 2015 at 04:00 PM 0
Share

I didn't actually write this specific script however, it does work some of the time but randomly seems to fail ever few $$anonymous$$utes of editing.

avatar image ThomasMarsh · Jan 04, 2015 at 04:39 PM 0
Share

I actually fixed my own issue. The referencing by tag did not work when I had multiple doors in the scene. I ins$$anonymous$$d changed it so that the script looks like this:

 #pragma strict
 public var thedoor: GameObject;
 
 function OnTriggerEnter (obj : Collider) {
     thedoor.animation.Play("open");
 }
 function OnTriggerExit (obj : Collider) {
    thedoor.animation.Play(“close”);
 }


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

2 People are following this question.

avatar image avatar image

Related Questions

Unity fire1 prefab in code 2 Answers

Script is working incorrectly. (rotation) 1 Answer

Prefab Instancing 2 Answers

Can't add a script to a prefab script: JavaScript 1 Answer

How to access script variables attached to a prefab at runtime in Javascript? 2 Answers


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