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 HPVal · Oct 11, 2013 at 02:34 PM · objectsame

Same script not working on all objects

So let me simplify it and make it clear so you can understand how ridiculous this is.

a) I have a script called "talking" with which you can interact with an object and a GUI will appear.

b) I have two planes with different textures, both with the script "talking".

c) The planes are EXACTLY the same, next to each other.

d) One works(1) the other doesn't(2), meaning when I interact with (1) the GUI pops up but when I interact with (2) it doesn't.

e) When I copy paste the (1) and insert the texture of the (2) the (2) magically works!

f) When I save my work, exit Unity and then reopen the scene (2) doesn't work.

g) When I redo step e) it works until I exit Unity again and reopen the scene.

I have many exact planes in my scene with the "talking" script. Half of them weren't working. So I did step e) and nearly all of them worked even after I exited Unity. Some are still not working though. I tried to create a new plane from start instead of copy/paste but it still doesn't work!

Why is this happening? Why some work and others don't? Oh and get this - the remaining scripts that don't work, when I do step e) they work! So there's no invisible collider or anything invisible that doesn't make them work, because they do. But after I exit Unity and restart it they are NOT WORKING? So what the...is going on!?

Sorry for the long post but please help because this is hilarious and EXTREMELY annoying!... Thank you!

Comment
Add comment · Show 17
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 mattssonon · Oct 11, 2013 at 02:36 PM 0
Share

Can you show the code for the script?

avatar image raimon.massanet · Oct 11, 2013 at 02:36 PM 0
Share

If you don't show any of your code it is very hard to say... $$anonymous$$aybe plane position in the world has something to do? $$anonymous$$aybe interaction time? Have you run the debugger to see if there is any exception thrown?

avatar image robertbu · Oct 11, 2013 at 03:01 PM 0
Share

Can you post the script?

avatar image HPVal · Oct 11, 2013 at 05:40 PM 0
Share

Yes the debugger says it's all fine...actually there's nothing wrong with the code since it works on the other planes. I have also tried changing the position of the planes but the results are the same. But here are both scripts: One is "talking" the other is "rayselect". I use the "rayselect" to recognize if an object has the "talking" script so I can interact with it.

"talking"

 var hud : boolean = false;
 var keydown : boolean = false;
 var $$anonymous$$ySkin : GUISkin;
 var subtitle : String = "(enter subtitle text)"; 
 //var boxheight: int;
 var boxsizeheight : int;
 var boxsizewidth : int;
 
 function Start () {
 
 
 }
 
 function Update () {
 hud=false;
 }
 
 function OnGUI ()
  {
 if (hud==true && keydown==true)
     {
 GUI.skin = $$anonymous$$ySkin;
 GUI.Box  (Rect ((Screen.width-boxsizewidth)/2,(Screen.height-boxsizeheight)/2,boxsizewidth,boxsizeheight), subtitle);
 } else {
 keydown=false;
 }
 }
 
     
     function OnLookEnter () {
     hud=true;
     keyhandle();
     }
     
 
     function keyhandle () 
     {
     if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.$$anonymous$$ouse0)==true) {
     if (!keydown){
     keydown=true;
         } else {
         keydown=false;
         }
     }
 }


"rayselect"

 using UnityEngine;
 using System.Collections;
 
 public class rayselect : $$anonymous$$onoBehaviour {
     public RaycastHit hit;
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
         Ray ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width/2, Screen.height/2, 0 ));
         if (Physics.Raycast(ray, out hit, 3)){
         if(hit.collider.gameObject.GetComponent<talking>() != null){
         hit.collider.gameObject.GetComponent<talking>().OnLookEnter ();
         
         }
         
     }
 }
 }
     

P.S: Thank you guys for helping!

avatar image HPVal · Oct 14, 2013 at 01:35 PM 0
Share

Hmm let me try that out and I'll let you know...thanks!

Show more comments

1 Reply

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

Answer by raimon.massanet · Oct 14, 2013 at 07:33 AM

I would say your problem has something to do with you re-setting the hud variable in Update. You are "activating" your talking script on OnGUI, but deactivating it on Update. So, maybe the problem is not that the script is not working, but you never get to see it working because it works only for a few milliseconds.

Why are you disabling hud in Update? I think you could handle all UI logic in OnGUI.

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

16 People are following this question.

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

Related Questions

trouble adding script to clone object 1 Answer

getting the object that the running script is attached to 1 Answer

Function action applies to every object that have script with that function on it. Help please 1 Answer

Ammo Script gives "object reference not set to an instance of an object" 1 Answer

reseting rotation of objects? 0 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