instantiate object to another class

I don’t remember. How can istantiate an GameObject of another class?

Game Manager Class

  private Stalactite[] stalactites; //stack stalactited
  
   void Start ()
  {
  Stalactite  test = Instantiate(new Stalactite().gameObject, new Vector3(0, 0, 0), Quaternion.identity) as Stalactite;
   }

Stalactite Class

public class Stalactite : MonoBehaviour
{
  void Update ()
  {
  this.transform.position = new Vector3(-Time.time, this.transform.position.y, this.transform.position.z);
   }

}

In Unity, Prefabs are analogous to classes. Also you don’t instantiate GameObjects using the ‘new’ keyword. Instead you build prefabs in the editor and reference them from a script responsible for their instantiation using Instantiate.

then I should put GameManager:

public Stalactite obj;

?

Almost. Stalactite is a MonoBehaviour, you want to instantiate the prefab (GameObject) that has this script attached to it, so it’s more straightforward to reference the gameObject instead:

public GameObject stalactitePrefab;

You don’t instantiate components with new. This is perfectly acceptable

GameObject go = new GameObject();
GameObject namedGo = new GameObject("My Object");

Depends. If I really care about some MonoBehaviour on a GameObject then I’d want a reference directly to that thing. Instantiate now has generic overloads so you can pass it MonoBehaviours or any other UnityEngine.Object derivative (you could do this before but you had to cast yourself and it wasn’t type safe). See the last examples on the doc page: https://docs.unity3d.com/ScriptReference/Object.Instantiate.html
So again, this is fine

Stalactite stal;

Stalactite newStal = Instantiate<Stalactite>(stal);
1 Like