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 Jamoy1993 · Jan 27, 2014 at 08:28 PM · rigidbodyactiveenabled

script wont re activate object when my conditions are met

What i am trying to do is set whether or not an object should be simulateded. If a player is within 100 units it should render and simulate the rigidbody, if not then it should disable the game object. However when i try to reactivate it will not work.

 @HideInInspector
 var PO : GameObject;
 @HideInInspector
 var D: Vector3;
 @HideInInspector
 var rendered : boolean = true;
 @HideInInspector
 var CT : float;
 
 var RenderDistance : float = 100;
 var CheckTime : float = 2;
 
 function Awake()
 {
     PO = GameObject.FindGameObjectWithTag("Player");    
 }
 
 function Update () 
 {
     
     CT += Time.deltaTime;
     if(CT >= CheckTime)
     {
         D = GameObject.FindGameObjectWithTag("DistanceProbe").GetComponent("PlayerDistanceMonitor").PlayerPosition;
         
         if(Vector3.Distance(transform.position, D) > RenderDistance)
         {
             gameObject.active = false;
         }
         
         if(Vector3.Distance(transform.position, D) < RenderDistance)
         {
             Debug.LogError("This is still working");
             gameObject.active = true; //however this isnt
             
         }
     }
     
 }

I have tried this also by just disabling the physics constraints and renderer. But when it reactivates the mesh renderer does not activate also... Any ideas?

Comment
Add comment
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

1 Reply

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

Answer by Armored13 · Jan 27, 2014 at 09:44 PM

Are you using Unity 4? If so, .active isn't something you're going to want to use. As discussed in THIS question, .active probably isn't going to work right. You can find more information about this HERE (a forum post discussing .active in Unity 4) as well as HERE (I think it's a blog, but it goes over some more details).

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

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

Related Questions

unity 2d trigger a script with a trigger? 0 Answers

Disabling GameObject doesn't disable components 0 Answers

Disabling/Enabling GameObjects with Attached Rigidbody Components leads to strange behavior 1 Answer

Active kinematic rigidbodies 2 Answers

'UnityEngine.Component.active' is obsolete. 4 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