Hi, i'm very new to unity, and as such, i was gonna make a basic demo, just to increase my skills, it should make the player capable of picking up certain items, and activating others, etc. etc.
Now, the key i used for picking up items was the 'E' key, like in many FPS. Being new, i just edited the "FPSWalker" script, which is a build-in, at least in my version of unity.
When testing and all that, it executed just fine, everything worked. I then tried to build it, and run it, and now the 'E' key seemed to only pick up the items once in a while. I then added the line: MoveDirection.y=jumpSpeed as a consequence for pressing the 'E' key, and still it only jumped sometimes, no saying when. The strange thing is still that in the unity editor, it all works fine, but as soon as i build it, the 'E' key only reacts sometimes, while any other key in the game (Which was already written in the build-in-script, not by me), works perfectly, and no lag is present, so it can't be any of those options, my script is as following:
var speed = 6.0;
var jumpSpeed = 8.0;
var gravity = 20.0;
var gem;
var altar;
var gui;
var Offer1=0;
private var moveDirection = Vector3.zero;
private var grounded : boolean = false;
function Start ()
{
gem=GameObject.Find("Obj1");
altar=GameObject.Find("Altar");
gui=GameObject.Find("GUI Text");
}
function FixedUpdate()
{
if (grounded)
{
// We are grounded, so recalculate movedirection directly from axes
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (Input.GetButton ("Jump")) {
moveDirection.y = jumpSpeed;
}
}
// Apply gravity
moveDirection.y -= gravity * Time.deltaTime;
if (Input.GetKeyDown(KeyCode.E))
{
moveDirection.y = jumpSpeed;
if (gem)
{
if (Vector3.Distance(transform.position,gem.transform.position)<2.5)
if (gem.GetComponent("MouseOver").MO==1)
{
Offer1=1.0;
Destroy(gem);
}
}
if (altar)
if (Vector3.Distance(transform.position,altar.transform.position)<3.2)
if (altar.GetComponent("MouseOver").MO==1)
if (Offer1==1)
{
gui.GetComponent("ShowLife").LifeUp(10);
Offer1=0;
}
}
// Move the controller
var controller : CharacterController = GetComponent(CharacterController);
var flags = controller.Move(moveDirection * Time.deltaTime);
grounded = (flags & CollisionFlags.CollidedBelow) != 0;
}
@script RequireComponent(CharacterController)