Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 kinggamer1235 · Sep 02, 2014 at 10:48 AM · c#activatecollider 2d

activate other objects inside a different objects script

Is there a way to activate an object inside another objects script by using SetActive?

I have posted questions about this before but have got replies saying the question wasn't very clear so this is as clear as I can make it.

Thanks in advance!

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

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Mikeywalsh · Sep 02, 2014 at 12:23 PM

You will receive an error if you try to set an object to active in your scene using GameObject.Find, as it will not be found(because it is inactive). You need to set up a reference to the object you wish to change in your script. Declare this at the top of your script:

 public GameObject target;

You can then assign your target to this new variable in the inspector. Then all you have to do to enable/disable the object is:

 target.SetActive(true);
 //or
 target.SetActive(false);



Comment
Add comment · Show 4 · 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 kinggamer1235 · Sep 02, 2014 at 03:11 PM 0
Share

sorry for being a bit of a noob but would i put the public GameObject target; bit in the objects script that i am trying to activate?

avatar image kinggamer1235 · Sep 02, 2014 at 09:16 PM 0
Share

oh wait figured it out, thanks so much!

avatar image Rocketman123 kinggamer1235 · Oct 12, 2016 at 10:41 PM 0
Share

um well i can't figure it out. could you explain? i'm kinda a noob.

avatar image rinomoen92 · Mar 02, 2020 at 08:49 AM 0
Share

This does not work for what i am trying to do.

i want to spawn an object that on collision activates 2 other game objects, but with this technique the GameObjects attached is removed on spawn, in other words i cant attach gameobjects already in the scene to a prefab waiting to be spawned

avatar image
0

Answer by frogsbo · Sep 02, 2014 at 11:03 AM

hiya, there are many questions on this, you have to devide it into two steps, "access gameobject from other script"

make a variable equals to other object using drag or gameObject.Find or trigger, etc

and then set active

 var hand = GameObject.Find("Hand");
 hand.... set active


i d recommend following tornado twins worm game tutorial and then becoming familiar with searching clues to a question with different phrases and familiar with reference.

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

OnMouseDown on Sprites (c#) 1 Answer

Can't create an Collider2D array? 1 Answer

A bunch of errors that I can't fix 1 Answer


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