Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Wesley21spelde · Aug 24, 2016 at 11:39 AM · enabledgameobject.findgetkey

scripting SetActive(true_false)?

Hey guys i have a problem with getting a deactivated gameobject to be reactivated

When i enter my atv everything works fine accept for the player it is still in the scene but turned off. my exit script can`t find it when i press F so how can i fix this?


 using UnityEngine;
 using System.Collections;
 
 public class Exit_ATV : MonoBehaviour {
 
 
     public GameObject Player;
     public GameObject ATVplayer;
     public GameObject ATV;
     public GameObject Trigger;
     public GameObject TriggerATV;
 
     // Use this for initialization
     void Start () {
         Player = GameObject.FindWithTag("Player");
         Player = GameObject.Find("Player");
         ATVplayer = GameObject.FindWithTag("ATVplayer");
         ATV = GameObject.FindWithTag("ATV");
         Trigger = GameObject.FindWithTag("Trigger");
         TriggerATV = GameObject.FindWithTag("TriggerATV");
     }
 
     // Update is called once per frame
     void Update()
     {
         if (Input.GetKey(KeyCode.F))
         {
             Player = GameObject.Find("Player");// Here is the problem! Player cant be found becouse it is set to SetActive(false) by my enter atv script
             Player.SetActive(true);
             ATVplayer.SetActive(false);
             ATV.SetActive(true);
             Trigger.SetActive(true);
             TriggerATV.SetActive(true);
 
         }
     }
 }
Comment
Add comment · Show 2
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 _Yash_ · Aug 24, 2016 at 11:34 AM 0
Share

1) take reference of Enter_ATV script in this and access player object of Enter_ATV which you found.
2) take reference of Exit_ATV in Enter_ATV and assign player reference of Exit_ATV when you find it in Enter_ATV.
3) keep an empty parent of player find that parent and use transform.getChild to get disabled child object.

avatar image Norfinity · Aug 24, 2016 at 11:41 AM 0
Share

Hi, use "Input.Get$$anonymous$$eyDown" ins$$anonymous$$d of "Input.Get$$anonymous$$ey"

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by saschandroid · Aug 24, 2016 at 11:52 AM

There are multiple solutions to this ... here are 2:

  1. Drag the GameObjects to the slots of the script (they are all public) and don't use GameObject.Find() in Start(). or

  2. Leave all the GameObjects active in the Inspector, use GameObject.Find() in Start() and deactivate the unwanted directly after finding them (also in Start() )

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

Does activating a parent activates children (MB's Awake()) 1 Answer

Selectively enable and disable Gamepads?,D 0 Answers

Could someone help me with my script? "How to translate object to a Vector3 of another object using raycast" 1 Answer

GetKeyDown Not Functioning When Two Unrelated GetKeys are True 0 Answers

Disable a C# script from another C# script. 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