Would a script like
Gameobject1 = Gameobject 2
I’m trying to make a gameobject hold a different object when a method is called and for some reason the above line isn’t working for me.
Would a script like
Gameobject1 = Gameobject 2
I’m trying to make a gameobject hold a different object when a method is called and for some reason the above line isn’t working for me.
You can point a GameObject reference at whatever GameObject you want.
Can you post your code using the forum code tags and copy/paste any errors so we can take a look at how you’re trying to do it? Or maybe this will be enough:
using UnityEngine;
public class GoGo : MonoBehaviour
{
public GameObject gameObjectReference;
public void SetReference(GameObject someGameObject)
{
gameObjectReference = someGameObject;
}
}
like mopthrow say we need to see what went wrong in your script so we can investigate and fix it
there is no one way to do Gameobject1 = Gameobject 2 there ton of it with different context and purpose
As long as you understand the differences between reference types (GameObjects are such a thing) and value types (structs or integers or floats, for example). One is effectively a finger saying “I am that” and the other is a fresh copy.
How to report your problem productively in the Unity3D forums:
How to understand compiler and other errors and even fix them yourself:
https://discussions.unity.com/t/824586/8
If you post a code snippet, ALWAYS USE CODE TAGS:
How to use code tags: https://discussions.unity.com/t/481379