Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Set parameters in the constructor while instantiating an object and specifying its components

Discussion in 'Scripting' started by calmcarrots, Aug 7, 2015.

  1. calmcarrots

    calmcarrots

    Joined:
    Mar 7, 2014
    Posts:
    654
    So I am instantiating an object and I am specifying its component. How do I call the constructor for Item?

    Here is the overloaded function that I'm calling:
    Code (csharp):
    1. public GameObject(string name, params Type[] components);
    And here is the line that creates the new object with the Item class. How do I call Item's constructor?
    Code (csharp):
    1. GameObject g = new GameObject("Item", typeof(Item));
     
  2. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
    calmcarrots likes this.
  3. calmcarrots

    calmcarrots

    Joined:
    Mar 7, 2014
    Posts:
    654
    Why the hell am I an idiot? like wtf how did I not think of this. how stupid do I have to be to not think of this? Please tell me. wow

    The Item class was originally not a monobehavior so that's why it had a constructor. But I totally forgot that once you have monobehavior, you have the start function. Wow I think Im going to sleep for the rest of the night
     
    ThermalFusion and GroZZleR like this.