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
3
votes
2 answers

Is there a way to check if all children of an object are active?

I am a beginner C# coder, and I am trying to make a game in Unity. Hence the question: Can I check if all children of an object are active in a scene? I want to use it to check if all enemies are active.
MegaRay_PL
  • 33
  • 1
  • 4
3
votes
1 answer

When setting a local scale to an instantiated gameObject, it loses material

I'm instantiating a gameObject from prefab, and I want to set local scale using code, but when I'm setting transform.localScale to the gameObject then it loses material and becomes black. public GameObject ballObject; public GameObject…
3
votes
1 answer

Unity rotate object depending on other objects angle

I have two Gameobjects. The basic Question: "When I spin circle 1, I want to spin circle 2 in the same way manipulated by factor x" How do I sync the rotation around each of their local axis of circle 2 with the interactable rotation of circle one…
Flo
  • 97
  • 10
3
votes
1 answer

How come the Collider falls from the GameObject when a RigidBody is added?

I could really need some help with my GameObjects. I am working on a game in which I want a pick-up Item to create a Physics Force explosion to blow away the enemies. I made a simple Bomb-Object to test this idea. I added a straightforward code,…
3
votes
1 answer

How to access a value from OnTriggerEnter2D in another function?

using System.Collections; using System.Collections.Generic; using UnityEngine; public class RedHP : MonoBehaviour { public float HP = 5; public GameObject BlueWon; public GameObject Restart; void OnTriggerEnter2D(Collider2D trig) …
klavyeadam
  • 123
  • 1
  • 3
  • 9
3
votes
1 answer

GameObject's Following a Leader / Centipede Issue

I am having difficulty chaining together some GameObjects to "Follow the leader". This is what I am trying to accomplish: Where there is a "head" object and it pulls the body objects with it. Like a snake or centipede. However, this is what is…
user-44651
  • 3,924
  • 6
  • 41
  • 87
3
votes
2 answers

What is the fastest way to get GameObject reference?

Let's say my script is defined as given below. public GameObject _GameObject; private void Start() { [![enter image description here][1]][1] _GameObject = gameObject; } Would this execute faster? public void SetActive(bool value) { [1]:…
Bora Kasap
  • 392
  • 4
  • 12
3
votes
2 answers

How do I get an object to move and swap places with another object, on a mouse clic

I have a script so far that moves an object a small distance upon a mouse click, however I want to change it so that when I click this object, it swaps places with another obejct next to it, instead of just the small distance it is moving now. I am…
Nicole Pinto
  • 364
  • 1
  • 22
3
votes
2 answers

Shift/offset texture used in material on GameObject?

I have a GameObject sphere in my program that represents the Earth. So I apply a material to it like so: Using data and a positioning script, I position markers on the globe that represent locations (by longitude and latitude). Everything seems to…
user6066644
3
votes
2 answers

Unity C# - Spawning GameObjects randomly around a point

I am not sure how to approach this problem or whether there are any built in Unity functions that can help with this problem so any advice is appreciated. Here is an image that'll help describe what I want to do: I want to spawn Game Objects around…
Mayron
  • 2,146
  • 4
  • 25
  • 51
3
votes
4 answers

Unity3D/C# - add a variable to gameobject

How can I add a variable to a GameObject? GameObjects have a series of variables (name, transform, ...) that can be accessed and modified from any script. How could I add a variable such as for example "color" or "type" that could be accessed or…
cubecube
  • 107
  • 1
  • 3
  • 8
3
votes
2 answers

Unity - best way to change the shape of the gameobject at runtime

I want create a simple 2D game in Unity3D, in which one of the entities has to grow and shrink. This is done by merging simple shapes. A rough example in the picture below just to show what I mean: It grows by adding components and shrinks by…
Raj Alahmar
  • 31
  • 1
  • 3
3
votes
3 answers

What is the most effective way to get closest target

What is the most effective and less expensive way to get closest target from these two methods? Using LINQ GameObject FindClosestTarget(string trgt) { GameObject[] closestGameObject = GameObject.FindGameObjectsWithTag(trgt) …
Sajitha Rathnayake
  • 1,688
  • 3
  • 26
  • 47
3
votes
3 answers

Setup hide / unhide GameOjbect in unity

I'm trying to setup a simple hide and unhide gameobject in Unity, but can't seem to get my coding to work correctly. What wrong with what I have written so far. #pragma strict public var myObject :GameObject; if (GUI.Button(new…
Coder
  • 499
  • 3
  • 13
  • 29
3
votes
1 answer

Unity: Prefab parenting in code

Let's say I want multiple prefab object called childTile, it parenting another single prefab object called parentTile. So whenever the parentTile rotates, childTiles will be rotated around parentTile. Basically this is what I wrote: public…
Sylphv
  • 43
  • 4
1 2
3
47 48