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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by Lilu · Aug 23, 2012 at 08:21 PM · gameobjectenablecondition

Game Objects enable problems

Hello, i have an 'if' condition and when it is true , i am trying to activate a game object and to enable a Script component on the same game object, and this is my code :

 var building7 : GameObject;
 building7.active = false;
  var target :Transform;
 if (distance>7 && target.position.x < -32)
        {
         building7.active = true;
           var findingbuilding7  : findingbuilding7 = building7.GetComponent("findingbuilding7");
         findingbuilding7.enabled = true;
         
         }
   

and the target is the main camera , and the code is attached to the main camera ,when i hit play the building dosen't activate ,but the script component enable.

i really can't figure out what i am doing wrong!!

thanks in advance for your help.

P.S : Sorry for my bad english

Comment
Add comment · Show 6
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 Mander · Aug 23, 2012 at 08:37 PM 0
Share

try to check if ur IF statement is working try to print something. is the script attached to the camera?

avatar image Lilu · Aug 24, 2012 at 08:48 AM 0
Share

i tried to print something Debug.log ("ok") , it is not working with the same condition , but when i change the condition to only : if (distance>7) it is working just fine ,

i want the Gameobject to be activated when the distance is bigger than 7 , and when the gameobject is in the field view of the camera thats why i added the condition 'target.position.x < -32 ' ....

and yes this script is attached to the camera.

thank you for your reply :)

avatar image GC1983 · Aug 24, 2012 at 09:11 AM 0
Share

Your na$$anonymous$$g conventions are all the same. You have a variable, class name and component all named the same. Thats bad form. Always name everything different, its helps to distinguish what you are using and it helps the editor from being confused.

You look like you are trying to turn on an object when the statement meets requirements. building7.active = true; might work better if you use var building7 : Renderer;. When you are making an object show and appear, you are manipulating the renderer object. This is the object that carries the mesh renderer. When you call a GameObject, you are calling for the whole piece, which doesnt let the editor find exactly what you are looking for.

Another thing. I would say to look for a GameObject and its component in a Start() or Awake(). It only needs to be called once to locate the object and their scripts for reference. From there you just call whatever scripts that are attached through the objectVariable.ExecuteWhatYouWant().

$$anonymous$$ake sense?

avatar image Lilu · Aug 24, 2012 at 09:49 AM 0
Share

first of all thank you for your advices , i am new to programmation and this helps me a lot .. :)

for turning on the game object , i tried building6.GetComponent($$anonymous$$eshRenderer).enabled = true; and it also didnt work. and i called the game object on Start() function.

i think that my problem is with the condition , target.position.x < -32 , because when i took this condition off evrey thing was working fine , is there another way to make sure that the building only activate if it is in the camera filed of view

avatar image Fattie · Aug 24, 2012 at 10:02 AM 0
Share

Your English is great !

$$anonymous$$uch better and more careful than 50% of native English writers.

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

10 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

Related Questions

How to enable children of child game object? 1 Answer

How to disable an array of projectors 2 Answers

enable scripts/ components on other gameobjects for a different gameobject? 1 Answer

Help With Disabling/Enabling single GameObject 1 Answer

Using raycast to "collide" with tagged objects & enable Halo Component 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