x


Create objects with script?

I have a Model that I've made with 3ds max, and a little game, I want to create that object in the character's position when I press "T" for example, how would I do that?

more ▼

asked Sep 10, 2012 at 12:55 PM

Lionlev gravatar image

Lionlev
53 8 17 19

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

You need to create a new game object and set its transform.position and .rotation to the character's position. Then you will need to add a MeshFilter component and a MeshRenderer component. The MeshFilter's shared mesh needs to be set to the object you created in Max.

public Mesh objectToCreate;

void Update()
{
    if(Input.GetKeyDown("T"))
    {
        var gameObject = new GameObject("Some Name Here");
        var meshFilter = gameObject.AddComponent<MeshFilter>();
        gameObject.AddComponent<MeshRenderer>();
        meshFilter.sharedMesh = objectToCreate;
        gameObject.transform.position = transform.position;
        gameObject.transform.rotation = transform.rotation;
    }
}
more ▼

answered Sep 10, 2012 at 01:57 PM

whydoidoit gravatar image

whydoidoit
53.4k 59 76 206

(comments are locked)
10|3000 characters needed characters left

First of all, you must make a Prefab that contains your 3DS Max model.

Then, you just need to instantiate it by using Instantiate in your script, you can even pass the position where you want your object to spawn.

more ▼

answered Sep 10, 2012 at 01:58 PM

hdgam3r gravatar image

hdgam3r
195 3 4 11

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x4827
x1733
x208
x28

asked: Sep 10, 2012 at 12:55 PM

Seen: 13137 times

Last Updated: Sep 10, 2012 at 01:58 PM