x


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.

more ▼

asked Jun 02 '12 at 12:01 AM

MinecraftUnity gravatar image

MinecraftUnity
0 4 4 4

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 :)

Jun 02 '12 at 12:23 AM whydoidoit

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:

Jun 02 '12 at 12:26 AM whydoidoit
(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
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:

x3463
x2207
x290
x95

asked: Jun 02 '12 at 12:01 AM

Seen: 770 times

Last Updated: Jun 02 '12 at 01:49 AM