I'm a noob. Can you help?

Ok. im a total noob at scripting, and more of the advanced features of Unity and C4D. I’m making a short and simple FPS Zombie game, ‘Biohazard’ and it will be super complex to make the AI and gun control scripts. But I’m gonna start simple. In the input manager, I assigned the ‘e’ key to be the function Interact. I put together a short simple script to test this. Like, this way when i push ‘e’, i can open doors, ask NPC’s to follow, ect…

Here a cube should move to from its coordinants to the ones in the script.

function Update () {
Input.GetKey ("Interact");
 transform.Translate (0,1 * Time.deltaTime,2 * Time.deltaTime);
 
	
}

But the console says ‘UnityException: Input Key named: Interact is unknown’ and when i hit play in the game view, the cube does nothing. Why? Sorry for my bad English… :smile:

Could you help?

It should be GetButton. GetKey uses the built-in Keycode variable like KeyCode.A.

Oh, ok, thanks. I did it, but now i applied it to a cube, and the cube just jumps around off the map, instad of moving to the place i want it to when i press ‘e’. I think its that the transform.Translate function isent applied to the GetKey function. is it, if so, what do I need to change? :shock:

If you’re making an fps there’s a good tutorial here:

http://unity3d.com/support/resources/tutorials/fpstutorial.html

I came across it when I started scripting a machine gun (as I am also a noob!)

good luck!

Just a quick warning, “biohazard” is trademarked (its what the resident evil games are called in japan), although that won’t be a problem unless you want to sell your game.

figured it out:

var dist = Vector3 (0, 0, 5);

function Update () {
   if(Input.GetButtonDown("Interact")) {
     transform.position += dist;
   }
}

But I still need to figure out how to make kit so i cant activate it from miles away, just when the camera is a certain distance away. Man, this scripting is hard! And what does Vector3 do anyway?

I might be able to help.

First off, you should really try to come up with better thread names, it helps people going thought to know what you need.

Second, the tutorial linked should really help you get going, I also would recommend that you read though the transformer tutorial and scripting references:

respectively.

About your question now:
Vector3 is a structure used to represent a three dimensional vector (see Unity - Scripting API: Vector3 for all the docs on it).
This little guy can store a point in space or represent a movement (like (1, 1, 1) can represent going forward 1 unit in every direction).
To do the thing where you cannot activate a button from too far away, you need two things:

  • the position of the button
  • the position of the activator (player usually)
    Once you have those, you can use Vector3.Distance to figure out the distance between them and then do a check to verify that they are close (otherwise ignore the ‘e’ call)

I think the first part of my post is more helpful (albeit less direct) then the second, try to check those out.