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 empath · Oct 06, 2013 at 04:11 PM · move an objectscriptable object

I need a script to disable/hide one child game object inside a parent when you exit a trigger collider.

Alrighty, so for some context:

I have a First Person Controller. It's children are Graphics and Main Camera. The First Person Controller has an inactive script called Rain Creator on it. The game starts. I move into 'Area1' and that causes Rain Creator to turn on. Rain Creator makes a clone of a prefab in my Assets (Heavy Rain) and then makes it a child of First Person Controller. I leave 'Area1' and the Rain Creator script turns off, but Heavy Rain (Clone) is still a child of First Person Controller.

So I want to add to the Rain Creator script that when I leave 'Area1' the child object 'Heavy Rain(Clone)' is hidden so that when I walk back into 'Area1' it will unhide that same child object. I do NOT want to delete/destroy the child object, because if I do the Rain Creator script will not make another when it gets re-activated.

Is there a way for a 'ForEach' loop to only target one child object and then disable it? I think that's what I need to do but I can't figure out how. C# preferred but I could probably get javascript to work as well.

P.S. These suggested tags are terrible for this post >_>

Comment
Add comment · Show 4
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 Jamora · Oct 06, 2013 at 04:18 PM 0
Share

-1, Unity Answers is not here to write your scripts for you. I will also do my best to downvote any answer that contains more than 5 lines of code.

avatar image empath · Oct 06, 2013 at 04:38 PM 0
Share

Well it seems to be here to help write scripts for everyone else, but you must fight for what you feel is right of course. I have not the time to learn coding from the ground up, I merely enjoy creating visions that I have seen in my $$anonymous$$d. If there are those that would help me accomplish my vision then I will always say more power to 'em.

avatar image aldonaletto · Oct 06, 2013 at 04:55 PM 0
Share

@Jamora, that's not a good policy: you would have to downvote 95% of my answers by this criterion! The same would apply to most answers from @Bunny83, @duck and many other posters (only the laconic answers from @Eric5h5 would survive!). $$anonymous$$an, don't be a Hitler!

avatar image Jamora · Oct 06, 2013 at 05:27 PM 2
Share

$$anonymous$$y policy is downvoting every question asking for a working, complete, script. I consider it very rude.

If someone asks for a little help in implementing a small feature and someone, out of the goodness of their heart, gives the OP working code, it's fine.

I think this question crosses that line between asking for a script and a little help, by outright asking for a script. Thus I'm taking a stand.

2 Replies

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

Answer by aldonaletto · Oct 06, 2013 at 04:25 PM

You should change a little your logic: instead of enabling/disabling RainCreator, activate/deactivate heavyRain (create it if necessary when entering Area1) - like this:

 using UnityEngine;
 using System.Collections;
 
 public class RainCreator: MonoBehaviour {

     public GameObject heavyRainPrefab; // heavy rain prefab

     private GameObject heavyRain;
       
     void OnTriggerEnter(Collider other){
         if (other.name == "Area1"){ // entering Area1:
             if (heavyRain){ // if heavyRain already exists...
                  heavyRain.SetActive(true); // activate it
             } else { // if doesn't exist yet, create it:
                  heavyRain = Instantiate(heavyRainPrefab, transform.position, transform.rotation) as GameObject;
             }
         }
     }

     void OnTriggerExit(Collider other){
         if (other.name == "Area1"){ // leaving Area1:
             heavyRain.SetActive(false); // deactivate heavy rain
         }
     }
 }
Comment
Add comment · Show 3 · 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 TrickyHandz · Oct 06, 2013 at 04:29 PM 0
Share

I removed my answer as the logic in this one is much more efficient.

avatar image empath · Oct 06, 2013 at 05:09 PM 0
Share

That script almost did it. I needed the created prefab to become a child of the First Person Controller and have it move to its location.

I added a 'public Vector3 localPosition;' and then under the instantiate I put heavyRain.transform.parent = transform; heavyRain.transform.localPosition = localPosition;

It now becomes a child and is moved to the Controllers location... but for some reason the rain prefab has become a super tiny slice, so it's like a 4x1 now ins$$anonymous$$d of a 4v4.

If I just normally place the prefab onto the controller it works, and if I use the old rain creator script to make a heavy rain prefab it works ($$anonymous$$eaning it's large), but for some reason even if I try and enlarge the one that is created by your script, it just gets taller, not wider.

Edit: Here are some pictures to try and explain a bit better, although it's nearly impossible to take them in my scene.

Working: http://i.imgur.com/D15Cymb.jpg

If you zoom in you can see tiny particles floating down in a large radius around the first person controller.

Not Working: http://i.imgur.com/UsiRRll.jpg

Now, only a very small straight line is cutting through the first person controller.

It dawns on me now that maybe I should've said the Heavy Rain prefab is a particle system? I don't know if that changes anything.

Edit: Edits are plentiful! The transform.rotation in the original script causes it to turn into a tiny slice, now I just need to figure out how to make it transform to an altered rotation or keep its original rotation and not adopt the rotation of the first person controller.

The Last edit!: I just removed the transform.position and transform.rotation from the instantiate line and now everything is right as rain! All puns intended! Thank you very much!

avatar image tw1st3d · Oct 06, 2013 at 05:21 PM 0
Share

try changing

 heavyRain = Instantiate(heavyRainPrefab, transform.position, transform.rotation) as GameObject;

to

  heavyRain = Instantiate(heavyRainPrefab, transform.position, heavyRainPrefab.transform.rotation) as GameObject;

so you're calling the rains rotation ins$$anonymous$$d of the players. This might fix it.

avatar image
0

Answer by rafasp · Oct 05, 2017 at 03:57 AM

You need Transform

Transform imageaux = gameobjaux.transform.Find("Image"); imageaux.gameObject.SetActive(false);

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

20 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

Related Questions

How to remove the oldest object 0 Answers

Rigidbody Not Move 0 Answers

Enable Instantiated Object 1 Answer

Scriptable object saves but what about objects it references? 0 Answers

Scriptable objects has empty inspectors and do not exist in build 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