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
4 answers

How to find all Cube game Object in the scene?

I'm looking for a way to find all CubeGameObject in the scene. I'm trying to do this : Cube[] ballsUp = FindObjectsOfType (typeof(Cube)) as Cube[]; But cube isn't a game object type apparently. I think i need to use something related to…
Helixb
  • 67
  • 1
  • 6
3
votes
2 answers

Is there a way two make two trigger gameObjects collide?

This is for a 2D game. I have a Player who can shoot trigger projectiles(with a trigger collider) and Enemies that can do the same. When a Player projectile collides with the Enemy, stuff happens and vice versa. However, when the Player projectile…
CodeLook12
  • 29
  • 1
  • 4
3
votes
2 answers

How to instantiate a : monobehaviour script from another GameObject

I'm having trouble figuring this one out and am finding little on google that helps me. In unity, if a script derives from MonoBehaviour, it cannot be instantiated using the "new" keyword. Fine. So I've been looking at how to do this, and it seems…
Matthew Goulart
  • 2,873
  • 4
  • 28
  • 63
3
votes
1 answer

How to create instances of a base character class

In order for a class to be attached to a GameObject it needs to inherit from MonoBehaviour. If I create a base character class that contains all the attributes shared by both NPCs and PCs, how do I create instances of that class and attach it to…
3
votes
2 answers

Set transform from another GameObject's script

I'm trying to make a script to set an object when is being instantiated. The problem is, I don't clearly know how to do it. I have this function.. function spawnPlayer() { var CameraScript =…
Oscar Reyes
  • 4,223
  • 8
  • 41
  • 75
2
votes
2 answers

The object of type 'BallMovement' has been destroyed but you are still trying to access it

I checked all over SO but couldn't find an answer that worked (or at least that I understood how to implement). I just started Unity not too long ago and I'm trying to make a Pong clone. The game work great on the first run, but when a player wins…
iceflare
  • 39
  • 4
2
votes
2 answers

Unity Trying to add image for graphic rebuild while we are already inside a graphic rebuild loop. This is not supported

I am working on a game in Unity, but recently I came across this unexplainable error, that pops up when I try to edit components of a GO child.. item.transform.GetChild(0).GetComponent().sprite =…
2
votes
0 answers

Stop specific animation from Animator

I am animating different gameobjects while using the same animator: public void Balances() { if (Monitors[0].activeSelf) { MonitorAnimations[0].Play("Monitor1-Animation", -1, 0f); …
IWOS
  • 77
  • 6
2
votes
1 answer

Bounds of GameObject after scaling

I'm writing a code in order to calculate the gameObject's box collider. When I use the method GetBounds() without scaling the object, the method work perfectly. Instead, if I scale the object (with localScale) and then launch GetBounds() method, the…
Zaki
  • 21
  • 1
2
votes
1 answer

Setting a prefab as child of another game object in unity

public GameObject aiArrow; aiArrow.transform.parent = this.gameObject.transform; When I try to set up a prefab as a child of another object the following error occurs. Setting the parent of a transform which resides in a Prefab Asset is disabled…
Savad
  • 1,240
  • 3
  • 21
  • 50
2
votes
0 answers

Assigning gameobject to array but thrown IndexOutOfRangeException

I have a system in place which looks an image, takes every pixel and generates a block to represent each pixel. I am currently in the process of optimising this by creating a combining mesh system so that all the thousands of cube objects are…
2
votes
4 answers

How to make a gameobject speed increase continuously when tapping quickly

so I am trying to achieve this feat of increasing my game object speed increase if I start tapping continually and then stop and get back to normal when I start tapping slowly. I am attaching a video below which have the cube and I have a sphere and…
Mingyu Kim
  • 127
  • 1
  • 11
2
votes
1 answer

How to use "OnClick.AddListener" on multiple GameObjects in one Frame

I'm pretty new to Unity and C# scripting. In my scene I have four buttons. I declared them in my script as public and put the items (on type Button) via drag and drop in my inspector in unity. Depending on which button is clicked, i want my program…
sm_1996
  • 27
  • 1
  • 3
2
votes
0 answers

When do you precede non-static GameObject methods and properties with gameObject in Unity?

For properties, layer needs gameObject to precede it but transform doesn't. For methods, SetActive() needs gameObject to precede it but GetComponent() doesn't. Second question: is there a convention to use gameObject.[method/property name] at…
2
votes
4 answers

How do I to know on which GameObject I clicked on Unity?

I want to make a Simple Memory Game using C# on Unity. It is a 2D game. I am trying to make a game in which the PC player clicks in a card, and then the game needs to call the function memory(GameObject card), but I don't know how to do and I can't…