- Home /
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 : )
Your answer
Follow this Question
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