- Home /
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.
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.
Answer by Andrew Cherkashin · Mar 23, 2010 at 01:05 AM
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);
anotherplayer.renderer.material = new $$anonymous$$aterial (Shader.Find("Transparent/VertexLit")); anotherplayer.renderer.material.mainTexture = Resources.Load("Sasuke", typeof(Texture2D)) as Texture2D;
Texture
Answer by straydogstrut · Mar 23, 2010 at 02:04 AM
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.
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.
Your answer
Follow this Question
Related Questions
Scaled sprite distorts on rotation in different resolutions 0 Answers
Weird Rotation Issue 0 Answers
postion scale and rotation greyed out and not working 1 Answer
Common 2D Collider flip problem 4 Answers