Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var purpleenemy : GameObject;
- var walkspeed : float = 0.8;
- var runspeed : float = 5;
- var ORwalkspeed :float = 0.8;
- var rotatespeed : float = 25.0;
- var character : GameObject;
- var jumpspeed : float = 1;
- var moveDirection : Vector3 = Vector3.zero;
- var gravity : float = 3.0;
- var pushpower: float = 3.0;
- var col :Collider;
- var watertexture : GUITexture;
- var mytransform : Transform;
- var driving = false;
- function Start ()
- {
- watertexture.enabled = false;
- driving = false;
- }
- function Update ()
- {
- //walk inputs
- var controller: CharacterController = GetComponent(CharacterController);
- if(controller.isGrounded)
- {
- if(driving == false)
- {
- transform.Rotate(0,Input.GetAxis("Horizontal") * rotatespeed * Time.smoothDeltaTime,0);
- moveDirection = Vector3(0,0,Input.GetAxis("Vertical"));
- moveDirection = transform.TransformDirection (moveDirection);
- moveDirection *= walkspeed;
- //jump
- if(Input.GetKey(KeyCode.Space))
- {
- Jump();
- moveDirection.y = jumpspeed;
- }
- if(Input.GetKeyUp(KeyCode.LeftShift))
- {
- Runspeed = ORwalkspeed;
- }
- //move animations
- if(Input.GetKey(KeyCode.W))
- {
- Walk();
- }
- if(Input.GetKey(KeyCode.S))
- {
- WalkBackWards();
- }
- if(Input.GetKeyUp(KeyCode.W))
- {
- Idle();
- }
- if(Input.GetKeyUp(KeyCode.S))
- {
- Idle();
- }
- if(Input.GetKey(KeyCode.LeftShift))
- {
- Idle();
- }
- }
- }
- if(!controller.isGrounded)
- {
- }
- controller.Move(moveDirection * Time.deltaTime);
- moveDirection.y -= gravity * Time.deltaTime;
- if(Input.GetKey(KeyCode.W) && Input.GetKey(KeyCode.LeftShift))
- {
- Run();
- walkspeed = runspeed;
- }
- //attack inputs
- if(Input.GetKeyDown(KeyCode.Mouse1))
- {
- R_punch();
- }
- if(Input.GetKeyDown(KeyCode.Mouse0))
- {
- L_punch();
- }
- }
- //push
- function OnControllerColliderHit(hit:ControllerColliderHit)
- {
- if(hit.gameObject.tag == "bunny")
- {
- hit.rigidbody.AddForce(mytransform.forward * pushpower);
- }
- if(hit.gameObject.tag == "enemy")
- {
- hit.rigidbody.AddForce(transform.forward * pushpower);
- }
- }
- //run/walk/idle animations
- function Walk()
- {
- animation["walk"].speed = 3;
- animation["walk"].wrapMode = WrapMode.Loop;
- animation.CrossFade("walk");
- }
- function WalkBackWards()
- {
- animation["walk"].speed = -3;
- animation["walk"].wrapMode = WrapMode.Loop;
- animation.CrossFade("walk");
- }
- function Idle()
- {
- animation["Idle"].speed = 1;
- animation["Idle"].wrapMode = WrapMode.Loop;
- animation.CrossFade("Idle");
- }
- function Jump()
- {
- animation["jump"].speed = 1;
- animation.CrossFade("jump");
- }
- function Run()
- {
- animation["run"].speed = 3;
- animation["run"].wrapMode = WrapMode.Loop;
- animation.CrossFade("run");
- }
- //attack animations
- function R_punch()
- {
- animation["right_attack_1"].speed = 8;
- print(animation["right_attack_1"].length);
- animation.CrossFade("right_attack_1");
- }
- function L_punch()
- {
- animation["left_attack_1"].speed = 8;
- print(animation["left_attack_1"].length);
- animation.CrossFade("left_attack_1");
- }
- function L_punchB()
- {
- animation["left_attack_1"].speed = -4;
- print(animation["left__1"].length);
- animation.CrossFade("left_attack_1");
- }
- //ontriggerenter for water gui texture
- function OnTriggerEnter(other:Collider)
- {
- if(other.gameObject.tag == "waterbox")
- {
- watertexture.enabled = true;
- }
- if(other.gameObject.tag == "enemycheckpoint1")
- {
- purpleenemy.GetComponent("purple enemy AI").disableobject = false;
- Debug.Log("disable object = false");
- }
- }
- function OnTriggerExit(other:Collider)
- {
- if(other.gameObject.tag == "waterbox")
- {
- watertexture.enabled = false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment