Questions tagged [gameobject]

GameObject is a key component of the Unity3D engine. It is often associated with Unity3D questions.

GameObject is a key component of the Unity3D engine. It is often used in the engine when developing games and apps. It can be added to a Unity scene to represent and control many game elements such as UI, audio, effects, lighting and various objects. The GameObject can have multiple components added to it, including a script to control its behavior and attributes.

708 questions
27
votes
5 answers

How can I find child gameobject?

I want to say somethings like.. Gameobject.find(child gameobject of specific parent Gameobject) Can anyone help me. thanks!
user3952722
23
votes
3 answers

Unity add child to children, but at top

I am trying to add a child object to a collection of children, but I want to make sure the the latest will be the first. Here is what I am trying to do: GameObject - (My new object here) - GameObject - GameObject - GameObject Here is the code I am…
Mansa
  • 2,277
  • 10
  • 37
  • 67
23
votes
2 answers

GameObject.FindObjectOfType<>() vs GetComponent<>()

I have been following several tutorial series and have seen these two used in very similar ways, and was hoping someone could explain how they differ and, if possible, examples of when you would use one instead of the other (presuming that they are…
JonHerbert
  • 647
  • 1
  • 8
  • 23
22
votes
2 answers

Add gameobject dynamically to scene in Unity3d

I am creating a scene in which I want to show list of offers. In order to show the offer, I created a prefab with placeholders for the offer details which I will get at runtime. I created a place holder in the scene to add the prefab to the scene,…
Ashwani K
  • 7,880
  • 19
  • 63
  • 102
12
votes
2 answers

Clone/duplicate an existing GameObject and its children

Is there a C# way in Unity to duplicate an existing GameObject and all of its children? In my case, I have an empty GameObject with a number of Text objects as children and I would like to create a copy of them all, including relative positions,…
Stephen Docy
  • 4,738
  • 7
  • 18
  • 31
11
votes
1 answer

Adding a shader to a gameobject

How can I add a shader to a game object? a have a shader defined here: (i am trying to do the same thing and am having some problems): http://answers.unity3d.com/questions/175692/getpixelsetpixels-or-stencil-eraser-brush.html and 2 texture2D defined…
Alex
  • 10,869
  • 28
  • 93
  • 165
8
votes
3 answers

Put a text onto a game-object BUT as if it was painted

I was looking for this answer on the web for some time. But apparently my search phrases were wrong or it is really that hard. But I doubt it. Imagine, I have any 3d-body. A sphere, cylinder or cube. I want to put a text onto that object. As if it…
icbytes
  • 1,831
  • 1
  • 17
  • 27
6
votes
1 answer

GameObject is destroyed by which script

I'm trying to find out my gameobject is being destroyed by which script in my game. So far i tried to print stack but details on script which is destroying the gameobject is not mentioned…
5
votes
3 answers

Why does Unity use transform instead of gameObject with some functions such as GetChild()?

Unity uses transform.GetChild(childNum) as opposed to gameObject.GetChild(childNum). I understand that every GameObject in Unity has a Transform component and the function returns the Transform of the child, but wouldn't it be more logical to use…
Roger Wang
  • 565
  • 2
  • 12
  • 30
5
votes
2 answers

Unity-How do I check if an object is seen by the Main Camera

I'm doing this thing where an object is moving on a plane, and the camera is in the center of it. I got it so the camera rotates along with the mouse, and when the main camera sees the game object, it stops. So I was using the onbecamevisible() and…
user8048595
  • 119
  • 1
  • 2
  • 12
5
votes
3 answers

Instantiating a GameObject causes said object to have its Transform destroyed?

New to Unity and C# This is actually just a small issue that I'm curious about... I ran into it while tweaking this code in a (failed) attempt to make it work. I have been trying to get this code to work for a few hours now. Anyway, when this code…
5
votes
1 answer

Share GameObjects between scenes

Let's assume I have a GameObject 'Player' and two scenes A and B. If I add this GameObject 'Player' on both scenes and then make some changes (e.g. adding a script in Scene A), can I somehow achieve that the GameObject 'Player' stays the same in…
Fabian Bigler
  • 10,403
  • 6
  • 47
  • 70
5
votes
3 answers

Using GetComponent to get a script using a string

Using the following code I am able to get the Script from "SMG" and apply it to the weaponObject: weaponObject = GameObject.FindGameObjectWithTag(SMG).GetComponent(); Is it possible to action something like the following and if so,…
user2740515
  • 89
  • 1
  • 2
  • 7
5
votes
2 answers

Unity3D - get component

What is the simplest way to getcomponent in Unity3D C#? My case: GameObject gamemaster. //C# script MainGameLogic.cs(attached to gamemaster). A boolean backfacedisplayed(in MainGameLogic.cs). A function BackfaceDisplay()(in…
sooon
  • 4,718
  • 8
  • 63
  • 116
5
votes
1 answer

Can't change public variables on a script attached to a gameobject. Values are restored upon play

Here is my first question. Haven't been able to find anything on the topic. I want to create an editor script that changes a number of public bools in a script that is attached to a GameObject. I have this script attached to a GameObject. The…
jake
  • 73
  • 1
  • 2
  • 6
1
2 3
47 48