Create Replication from Unity 2D prefab

Asked 1 years ago, Updated 1 years ago, 96 views

Unity 5.3
What you want to do is "replicate and view prefabricated"

GameObject prefab=(GameObject)Resources.Load("Prefabs/hoge");

You can see that the gets prefabricated.
Next,

Instantiate(prefab, tran.position, Transform.rotation);

You get an error when you do .I thought the argument part might be a problem, so I did the following:

Instantiate(prefab,0,0);

Why doesn't it work even though I copied it from the point of creating an instance?

using UnityEngine;
using System.Collections;

public class start:MonoBehavior {
    // Get prefabricated
    GameObject prefab=(GameObject)Resources.Load("Prefabs/hoge");
    // Instantiate (prefab, tran.position, Transform.rotation);
    Instantiate (prefab, 0, 0);
}
Asset/Script/Start.cs (8,29): error CS1519: Unexpected symbol `0' in class, structure, or interface member declaration
Assets/Script/Start.cs (8,21): error CS1041: Identifier expected

unity3d unity2d

2022-09-30 16:02

1 Answers

It's hard to answer because there are too many folds, but please try the following:

Instantiate (prefab, tran.position, Transform.rotation);

First of all, I don't know what the two arguments are meant to be.

tran.position

Where is the tran from?

Transform.rotation

I understand that this is taken from the GameObject that I have set up somehow.

First of all, I would like to assume that the setting probably has no intention.
Therefore,

Instantiate (prefab);

Please try it here.
The last two arguments work without .

Instantiate (prefab, 0, 0);

I think it's probably because the argument is not correct, but
As there is no script before and after, I will refrain from commenting.

Try each one.


2022-09-30 16:02

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.