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 Samuel411 · Oct 07, 2013 at 03:17 AM · parentchildgameobjectsenablenetworkview

How can I make code work on a disabled object

I am working on a multiplayer FPS. In the FPS perspective you see your gun and your hands. Other players will see a soldier holding a gun. I want to add a mouse look to the spine so when you look up or down the soldier will also look up and down. I cant seem to do this if I disable the spines parent. There is a player handler running the show, it turns on or off gameobjects and scripts if the networkView is yours or not, these include the FPS view and the soldier view, any help would be appreciated, I could turn each of the soldiers objects off but that would be not productive.

Comment
Add comment · Show 3
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 robertbu · Oct 07, 2013 at 03:26 AM 0
Share

InvokeRepeating() does not get disabled when a game object is disabled. I don't understand your full setup, but you might be able to execute you mouse look code in an InvokeRpeating().

avatar image Samuel411 · Oct 07, 2013 at 03:56 AM 0
Share

Heres the code to the PlayerHandler (JS) (tpsView is what other people see you as)

 #pragma strict
      
 var fpsView : GameObject;
 var tpsView : GameObject;
      
 function Start () {
       Screen.lockCursor = true;
       Screen.showCursor = false;
       if(networkView.is$$anonymous$$ine == true){
          fpsView.active = true;
          tpsView.active = false;
          transform.GetComponent($$anonymous$$ouseLook).enabled = true;
          transform.GetComponent(FPS$$anonymous$$ovement).enabled = true;
          transform.GetComponent(DisconnectButton).enabled = true;
       }else{
          fpsView.active = false;
          tpsView.active = true;
          transform.GetComponent($$anonymous$$ouseLook).enabled = false;
          transform.GetComponent(FPS$$anonymous$$ovement).enabled = false;
         transform.GetComponent(DisconnectButton).enabled = false;
       }
 }
      
 function Update () {
      if(networkView.is$$anonymous$$ine == true){
         fpsView.active = true;
         tpsView.active = false;
         transform.GetComponent($$anonymous$$ouseLook).enabled = true;
         transform.GetComponent(FPS$$anonymous$$ovement).enabled = true;
         transform.GetComponent(DisconnectButton).enabled = true;
      }else{
         fpsView.active = false;
         tpsView.active = true;
         transform.GetComponent($$anonymous$$ouseLook).enabled = false;
         transform.GetComponent(FPS$$anonymous$$ovement).enabled = false;
         transform.GetComponent(DisconnectButton).enabled = false;
      }
 }
 

And I am using the $$anonymous$$ouseLook.cs that came with unity

avatar image Hunter_Bobeck · Jun 30, 2018 at 07:32 PM 0
Share

I found that using Invoke will still run the invoked method once it's time to, even if the object (whose script component the invoked method is on) has since been disabled sometime after the Invoke was called.

1 Reply

· Add your reply
  • Sort: 
avatar image
3

Answer by venusboysatish · Oct 07, 2013 at 07:51 AM

You can not make a script run on a disabled object. instead of disabling the object, disable the components that you don't want to act upon. for example, if you don't want it to be displayed in the game, disable its Renderer component, if you don't want it to collide, disable its collider, and so forth. hope this helps.

Comment
Add comment · Show 1 · 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 Samuel411 · Oct 07, 2013 at 09:30 PM 0
Share

But I want other people to see you and have the bullets damage you as well.

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

17 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 avatar image

Related Questions

Make a simple tree 1 Answer

Why GameObject.Find() work and parent.transform.Find() doesn't work? 1 Answer

what happens when Unit in Hierarchy is destroyed? 1 Answer

How do you select a root object from a child's script? 1 Answer

Accessing a child's animation to play or stop it 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