x


Object Creation

I have script that create GameObject. What i want:

  • Create that object [x]
  • Give a name [x]
  • Put in right position [x]
  • Rotate [x]
  • Change size [x]
  • Put texture on it [ ]

I need a c# solution.

more ▼

asked Mar 23 '10 at 12:46 AM

Andrew Cherkashin gravatar image

Andrew Cherkashin
53 6 6 15

Your question could have been made more general by splitting it up into simpler questions. Please see this section in the faq: Break multi-part problems into simpler questions.

Mar 23 '10 at 02:33 PM runevision ♦♦
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

Everything expect texture:

                anotherplayer =  GameObject.CreatePrimitive(PrimitiveType.Plane);
                anotherplayer.name = updatexml.players[i].username;
                anotherplayer.transform.localScale = new Vector3(0.0903f, 0.0903f, 0.0903f);
                anotherplayer.transform.eulerAngles = new Vector3(62.68924f, 184.4452f, 4.010004f);
                anotherplayer.transform.position = new Vector3(updatexml.players[i].x_coordinate, updatexml.players[i].y_coordinate, updatexml.players[i].z_coordinate);
more ▼

answered Mar 23 '10 at 01:05 AM

Andrew Cherkashin gravatar image

Andrew Cherkashin
53 6 6 15

anotherplayer.renderer.material = new Material (Shader.Find("Transparent/VertexLit")); anotherplayer.renderer.material.mainTexture = Resources.Load("Sasuke", typeof(Texture2D)) as Texture2D;

Texture

Mar 28 '10 at 12:35 AM Andrew Cherkashin
(comments are locked)
10|3000 characters needed characters left

For assigning a texture to the object, I believe you can use the following (Javascript) placed on the object in question:

var myTexture: Texture2D; 

function Start(){ 

    renderer.material.mainTexture = myTexture;
}

A similar forum post and the Unity Scripting Reference.

I don't know C# unfortunately but this post would seem to suggest you can use a similar line like the following:

public Texture mytexture; 

void Start() 
{ 
   renderer.material.mainTexture = mytexture; 
}

Hope that helps.

more ▼

answered Mar 23 '10 at 02:04 AM

straydogstrut gravatar image

straydogstrut
1.2k 29 38 60

okey, but what's value of mytexture?

Mar 24 '10 at 05:37 AM Andrew Cherkashin

Sorry for the tardy reply, you've probably worked it out by now, but incase you haven't: 'myTexture' is a variable for storing a reference to the texture you want to put on the object. In the example, the JS one at least, it should show in the Inspector and allow you to choose a texture by dragging it into the slot.

Mar 28 '10 at 06:59 PM straydogstrut
(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:

x2171
x388
x141

asked: Mar 23 '10 at 12:46 AM

Seen: 1003 times

Last Updated: Mar 23 '10 at 01:07 AM