1
\$\begingroup\$

I'm new to unity.

How can I make some copies of my GameObject in Unity by scripting?

I have tried this by the way:

public GameObject stone_3;

void Start ()
{
  for (int i = 0; i < 10; i++)
    Instantiate(stone_3, new Vector3(i * 2.0f, 0, 0), Quaternion.identity);
}

I can't really understand why it's not working.

\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

There may be two reasons why it's not working.

  1. You have not attached the script to any object which is in the hierarchy window.
  2. You have not assigned a prefab in the stone_3 variable field.
\$\endgroup\$
3
  • 1
    \$\begingroup\$ Yep, the code looks like it should work, I don't think the code is the issue. However, the second item would be displaying an error on the debug log. Something along the lines of "The thing you're trying to instantiate is null". The second item can only be experienced if the first is not the problem, so it's probably the first item. \$\endgroup\$
    – House
    Jul 22, 2016 at 17:36
  • \$\begingroup\$ New users may miss console window sometimes. That's why I put the second reason as it's not a compile error. \$\endgroup\$ Jul 22, 2016 at 17:40
  • \$\begingroup\$ Yeah both are good, since it nips the follow up question of why it's still not working. \$\endgroup\$
    – House
    Jul 22, 2016 at 18:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .