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 Digital-Phantom · Dec 17, 2014 at 03:05 PM · prefabhierarchyobject-child

Why Does this Work on a Hierarchy Object but NOT a Prefab?

Why does this script only work on objects/child objects I drag and drop from the hierarchy and not on ones I drag from my prefabs?

 #pragma strict
 
 var torch : GameObject;
 
 function Start ()
 {
     torch.SetActive(false);
 }
 
 function OnTriggerEnter()
 {
     torch.SetActive(true);
 }
 
 function OnTriggerExit()
 {
     torch.SetActive(false);
 }


(the script is used to make it so the lights in a room/area only come on when the player is in that area)

Thanks

Comment
Add comment · Show 5
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 taxvi · Dec 17, 2014 at 03:25 PM 2
Share

because prefab does not exist in the scene unless you instantiate it in the scene with the Instantiate() method. look it up in the unity references. :))

avatar image Digital-Phantom · Dec 17, 2014 at 03:33 PM 0
Share

All the items are already in the scene. All I basically want to do is turn the flames on (make them active) when the player enters that game area and turn off once the player leaves the area

avatar image taxvi · Dec 17, 2014 at 03:38 PM 1
Share

if you first drop the prefab in the scene and then drop the same prefab on the 'torch' slot that won't work. you need to select the object in the scene and drop it on the 'torch'.

avatar image Digital-Phantom · Dec 17, 2014 at 03:56 PM 0
Share

Which works fine for that one item. But I have 6 torches/flames in the room. Only the specific one I drag over is affected, not all of them?

avatar image taxvi · Dec 17, 2014 at 04:00 PM 0
Share

ok, then this is not so professional but easily understandable way: create 6 variables called torch1 torch2 torch3... and implement all the sentences that you have for your torch for each of the torches.

if you know arrays and for loops you can achieve the same effect by introducing an array of GameObjects and looping each enabled/disabled commands through all of the using the for loop, google arrays and google 'for loops' for more info

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Paulocmfo · Dec 17, 2014 at 07:31 PM

Through code you only can put a prefab in scene through Instantiate() method. See script reference for 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

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

Related Questions

How to destroy all gameobjects active in hierarchy? 1 Answer

Check if game object is active in hierarchy from a prefab 2 Answers

Adding extra bones to an already imported and prefab'ed character. 1 Answer

GameObject is missing a prefab, assign prefab to gameobject 1 Answer

Why cannot I drag and drop a gameObject from Hierarchy to a prefab's slot in the Inspector? 3 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