- Home /
How to make a Cube with a texture in a JavaScript?
I am completely new to Unity 3D. I own the free version. For my first project, I am trying to make a MineCraft like clone. I followed tutorials, but now i'm trying to change something so it works how I want it. First off, how can I place a cube with a texture on it? Here's a chunk of code where I need to be able to do this:
function Build() {
if (HitBlock()) {
var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
cube.transform.position = hit.transform.position + hit.normal;
}
}
This spawns a default cube with no texture whatsoever. How do I get a texture?
Next, how to I add an arm that follows me around with animation. I know I have to parent it to First Person Controller > Main Camera... But, what do I do for animations? And I have a gun, but I want it only to appear when I press a key, or press a key to get rid of this.
Third, for deleting a brick, how can I force the user to click, but hold down for X amount of time before the Cube breaks? I have an instant delete chunk of code here:
function Erase() {
if (HitBlock())
Destroy(hit.transform.gameObject);
}
I know absolutely NO javascript, or java, so I came here.
Hi there - welcome on board :)
Just a note - it is a really good idea to ask more than one question when your questions are so different to each other. This is a knowledge base rather than a forum and so it matters that answers clearly follow the heading of the topic.
Also, you will find different people will be able to help of different questions but will be put off by not being sure about all of the answers.
So - please read the FAQ and please feel free to ask each question individually, with as much clarity and detail as possible :)
Next point actually is that if you aren't a programmer at all then you will probably be frustrated with the answers or lack of them that you get here. If you are just new to UnityScript (which is somewhat different to Javascript and a whole lot different to Java! - Sorry to tell you) then you might be better off doing some of the tutorials that are available or muddling through.
Tutorials:
Your answer
Follow this Question
Related Questions
How do I put a texture on my Cube using code (JavaScript) 1 Answer
Primitive Cube Texturing Help 3 Answers
how to change the maintexture from another scene? 1 Answer
Assigning UV Map to model at runtime 0 Answers
Screenshot to variable 1 Answer