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 Prototyper12 · Jun 17, 2015 at 03:20 AM · scripting problemgameobjectgetcomponentvuforiasyntax-error

Learning Unity : GameObject Activation/DeActivation & Calling Components of child of another GameObject

Unity Beginner : using Unity 4.6.3 along with Vuforia 4.2.3 for building Android AR application. Don't know scripting.

Process I follow for basic setup: I perform the following actions; [1] Open Unity and Create a New Project [2] Delete Main Camera [3] Import Packages - Vuforia Unity 4.2.3 AR Package and relevant ImageTarget Database packages, in the assets. [4] Put an AR Camera Prefab to the "Hierarchy" section of Unity. Enter the linked Vuforia License Key. Select the appropriate database and activate it. [5] Put an ImageTarget in the "Hierarchy" section of Unity. Load the appropriate database for the same. [6] Create a child of the ImageTarget GameObject, say a sphere I named 'BigBall'. [7] Create a Button in the "Hierarchy" section of Unity. The Canvas, the button belongs to is on "ScreenSpace-Overlay" setting. [8] Now the problem begins...When I PLAY(press the play button) the game, upon detection of the AR Marker, by the camera the sphere is seen in the Game View. And the Button is also present on the screen, due to ScreenSpace-Overlay.

I want but is NOT happening I'd like that the cube should disappear when I click the button or to say if the user taps the button.

I have tried: Related to GameObject Activation/De-Activation: I have gone through the Documentation/Manuals/Scripting APIs all for [1] learning how to activate/deActivate a GameObject. I thought I will create a Script Component in the 'BigBall' object with the GameObject.SetActive(false) in the Start(). Use this function in the Button's On Click() and in-there call the hide() - THIS DID NOT WORK :( Code Attached

     using UnityEngine;
     using System.Collections;
     
     public class HideSphere : MonoBehaviour {
     
         public BigBall bigBall;
     
          // Use this for initialization
         void Start () {
         bigBall.SetActive(false);
         }
 
         void hide(){
          bigBall.renderer.enable = !bigBall.renderer.enable;
           }
 
     }

[2] I thought I will create a component script in the Button, which I renamed "Hide". The script would look for the component material from sprite renderer that would have the alpha value which I can change on click of the button i.e. Hide, to make the sphere disappear. - DID NOT WORK :( Code Attached.

  using UnityEngine;
  using System.Collections;
 
  public class Hide : MonoBehaviour {
 
     public Hide hide;
 
      // Use this for initialization
     void Start () {
     hide = GetComponentsInChildren<ImageTarget.Sphere>();
     }
 }


Stuck Point - I am 4 days old in to coding and I am from a design background. I don't know the syntaxes very well. I am facing these issues [1] I don't understand that in some examples of Unity ScriptingAPI, they mention code samples like public GameObject gameObject; . Now is this the way to write it? I mean if my GameObject in the Hierarchy is called BubbleGum, will I write "public GameObject gameObject;" while scripting or "public BubbleGum bubbleGum;".

[2] 2 ways I thought I'll approach the problem of making the sphere/BigBall disappear - [A] To create a component script in the sphere object and call it on the Button OnClick() and deactivate the GameObject. [B] To create a component script in the Button which will get the component of the child(i.e. of BigBall) of the other GameObject(i.e. of ImageTarget). Change value of the variable within the component to make it disappear. ................................................................................. Question Which of the above 2 approaches is more sensible and quicker ?

[3] Can you please offer me the syntax in return of my queries rather than generalised understanding because MonoDevelop doesn't seem to understand the general understood statements?

I have posted a rather long query but then since I don't have anybody around me who gets Unity or Coding, I thought I should explain the problem well.

Looking forward to answers. Please put your suggestions for improving the question in the comments below.

Thanks a lot in advance.

Please help : )

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

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

2 People are following this question.

avatar image avatar image

Related Questions

Timer for destroying/ appearing Gameobject (Vuforia) 2 Answers

GameObject is already being activated or desactivated 2 Answers

Loading AssetBundles from inside the Project 1 Answer

How to make an object invisible before it is triggered to show? 2 Answers

One script for many Game Objects with different values 0 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