Ok, so I'm having trouble with making my ball move in Unity using the keyboard for a simple game I'm doing...I've been at this for hours now and I cannot figure out for the life of me what the problem is with the script. I am a COMPLETE beginner when it comes to this stuff so I have no idea how to do it. All I do know is that Javascript is preferred. Here's what I've got right now:
#pragma strict
//Private variables
private var rb:Rigidbody;
private var offset:Vector3;
private var cam:GameObject;
//Public variables
public var speed:float = 5;
//Start function
function Start () {
//Gets the rigidbody component
rb=GetComponent.();
//Main game camera
cam = Camera.main.gameObject;
offset = cam.transform.position - transform.position;
}
//Update function
function Update () {
}
//Late update function
function LateUpdate(){
cam.transform.position = transform.position + offset;
}
//Fixed update function
function fixedUpdate() {
var moveHorizontal:float = Input.GetAxis("Horizontal");
var moveVertical:float = Input.GetAxis("Vertical");
var movement:Vector3 = new Vector3(moveHorizontal, 0, moveVertical);
//Lets the player move around the maze
rb.AddForce(movement * speed);
}
//Trigger enter function
function OnTriggerEnter(other: Collider){
Debug.Log(other.gameObject.tag);
//Win if statement
if (other.gameObject.tag == "Trigger Goal"){
Debug.Log("I win!");
}
//Lose if statement
else if(other.gameObject.tag == "Trigger Lose"){
Debug.Log("I lose...");
transform.position = new Vector3(0, 0.5, 0);
rb.angularVelocity = rb.velocity = Vector3.zero;
}
other.gameObject.active = false;
}
Any and all help is appreciated. ,
↧