- List item
So, I am Trying To make A temple run game
and i am not able to jump or make it go side ways
Please Help
following is my Script
public var speed = 10.0f;
var jumpSpeed = 20.0f;
var gravity =20.0f;
private var moveDirection = Vector3.zero;
private var grounded :
boolean = false; var coin = 0; var
coinText = "coin: 0";
var sideSpeed =12;
function Start(){ // Set all
animations to loop
animation.wrapMode = WrapMode.Loop;
// except shooting
animation["side"].wrapMode =
WrapMode.Once;
animation["side"].layer = 1;
animation["jump"].wrapMode =
WrapMode.Once;
animation["jump"].layer = 2;
animation.Stop(); }
function FixedUpdate() {
if (grounded) {
if (Mathf.Abs(Input.GetAxis("Vertical")) <= 0.1){
animation.CrossFade("run");
}
}
// 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.GetButtonDown("side")){
animation.CrossFade("side");
}
if(Input.GetButtonDown("Jump")) {
moveDirection.y = jumpSpeed; }
if(Input.GetButtonDown("Jump")) {
animation.CrossFade("jump");
}
// Apply gravity moveDirection.y -=
gravity * Time.deltaTime;
// Move the controller
` `var controller
: CharacterController =
GetComponent(CharacterController); var
flags = controller.Move(moveDirection
* Time.deltaTime); grounded = (flags & CollisionFlags.CollidedBelow) != 0;
`` }
@script
RequireComponent(CharacterController)
function Update() {
transform.position +=
transform.forward * speed *
Time.deltaTime;
speed += 2.0 * Time.deltaTime; }
function OnTriggerEnter( other : Collider ) {
Debug.Log("OnTriggerEnter() was called");
if (other.tag == "Gold") {
Debug.Log("Other object is a coin");
coin += 1;
coinText = "Score: " + coin;
Debug.Log("Score is now " + coin);
Destroy(other.gameObject);
}
if (other.tag == "Blue") {
Debug.Log("Other object is a coin");
coin += 2;
coinText = "Score: " + coin;
Debug.Log("Score is now " + coin);
Destroy(other.gameObject);
}
if (other.tag == "Red") {
Debug.Log("Other object is a coin");
coin += 3;
coinText = "Score: " + coin;
Debug.Log("Score is now " + coin);
Destroy(other.gameObject);
} }
function OnGUI () {
GUI.Label (Rect (10, 10, 100, 20), coinText);
}