// Copy constructor. public RunnerAbility(RunnerAbility src) { this.WalkSpeed = src.WalkSpeed; this.WalkSpeedAtJump = src.WalkSpeedAtJump; this.Gravity = src.Gravity; this.JumpSpeed = src.JumpSpeed; }
public override void apply(RunnerAbility ability) { ability.WalkSpeed += 24.0f; ability.WalkSpeedAtJump += 24.0f; }
// Update is called once per frame void Update() { if (BRGameStatus.Instance ().gameStatus () != enumGameStatus.RUNNING) { return; } if (stop) { return; } CharacterController controller = (CharacterController)GetComponent ("CharacterController"); RunnerAbility ra = new RunnerAbility (runnerAbility); checkSpecialTechniquesTrigger (); // apply all buffs buffContainer.applyAllBuffs (ra); buffContainer.updateBuffs (Time.deltaTime); if (keyboardInput) { horizontalDirection += Input.GetAxis ("Horizontal"); if (horizontalDirection > horizontalDirectionLimitPositive) { horizontalDirection = horizontalDirectionLimitPositive; } if (horizontalDirection < -horizontalDirectionLimitPositive) { horizontalDirection = -horizontalDirectionLimitPositive; } // make direction and turn to it. Vector3 directionVector = new Vector3 (horizontalDirection * 0.1f, 0.0f, 1.0f).normalized; /* Debug.Log (string.Format ("directionVector=({0},{1},{2})", directionVector.x, directionVector.y, directionVector.z)); */ controller.transform.LookAt (directionVector + controller.transform.position); if (controller.isGrounded) { velocity = new Vector3 (0, 0, 0); if (Input.GetButtonDown ("Jump")) { Debug.Log ("Animation : Jump"); velocity.y = ra.JumpSpeed; if (animation) animation.CrossFade ("Jump", 0.1f); } else { if (animation) { if (animation.IsPlaying ("Walk") == false) { animation.CrossFade ("Walk", 0.1f); //Debug.Log ("Animation : Walk"); } } } } // make move to direction + jump up Vector3 nextPositionVector; if (controller.isGrounded) { nextPositionVector = directionVector * ra.WalkSpeed; } else { //Debug.Log ("at Jump!!!"); nextPositionVector = directionVector * ra.WalkSpeedAtJump; } velocity.y -= (ra.Gravity * Time.deltaTime); nextPositionVector.y = velocity.y; controller.Move (nextPositionVector * Time.deltaTime); } else { int sw = Screen.width, sh = Screen.height; bool jump = false; float horizontalAxis = 0.0f; if (Input.touches.Length == 1) { // skip if buff activation area is touched Vector2 touchPos = Input.touches[0].position; if (rectMoveTouchIgnore.Contains (touchPos)) { // ignore this. Debug.Log ("trace~~~"); } else { if (Input.touches [0].position.x < sw / 2) { // left horizontalAxis = -0.16f; } else { // right horizontalAxis = 0.16f; } } } else if (Input.touches.Length >= 2) { // make jump jump = true; } horizontalDirection += horizontalAxis; if (horizontalDirection > horizontalDirectionLimitPositive) { horizontalDirection = horizontalDirectionLimitPositive; } if (horizontalDirection < -horizontalDirectionLimitPositive) { horizontalDirection = -horizontalDirectionLimitPositive; } // make direction and turn to it. Vector3 directionVector = new Vector3 (horizontalDirection * 0.1f, 0.0f, 1.0f).normalized; /* Debug.Log (string.Format ("directionVector=({0},{1},{2})", directionVector.x, directionVector.y, directionVector.z)); */ controller.transform.LookAt (directionVector + controller.transform.position); if (controller.isGrounded) { velocity = new Vector3 (0, 0, 0); if (jump) { Debug.Log ("Animation : Jump"); velocity.y = ra.JumpSpeed; if (animation) animation.CrossFade ("Jump", 0.1f); } else { if (animation) { if (animation.IsPlaying ("Walk") == false) { animation.CrossFade ("Walk", 0.1f); //Debug.Log ("Animation : Walk"); } } } } // make move to direction + jump up Vector3 nextPositionVector; if (controller.isGrounded) { nextPositionVector = directionVector * ra.WalkSpeed; } else { Debug.Log ("at Jump!!!"); nextPositionVector = directionVector * ra.WalkSpeedAtJump; } velocity.y -= (ra.Gravity * Time.deltaTime); nextPositionVector.y = velocity.y; controller.Move (nextPositionVector * Time.deltaTime); } // check boundaries bool needRepositioning = false; Vector3 pos = controller.transform.position; if (pos.x > (10.0f - 1.2f)) { pos.x = (10.0f - 1.2f); needRepositioning = true; } if (pos.x < (-10.0f + 1.2f)) { pos.x = (-10.0f + 1.2f); needRepositioning = true; } if (needRepositioning) { controller.transform.position = pos; } }
// Use this for initialization void Start() { if (animation) { animation ["Walk"].speed = 5.0f; } runnerAbility = new RunnerAbility (); buffContainer = new BuffContainer (); tmpBuff = new Buff_SpeedBoost (); int sw = Screen.width, sh = Screen.height; //rectMoveTouchIgnore = new Rect (0, sh - tmpBuff.IconTexture.height, tmpBuff.IconTexture.width * 3, tmpBuff.IconTexture.height); rectMoveTouchIgnore = new Rect (0, 0, tmpBuff.IconTexture.width * 3, tmpBuff.IconTexture.height); Debug.Log(string.Format("rectMoveTouchIgnore={0}", rectMoveTouchIgnore)); }
public virtual void apply(RunnerAbility ability) { }
public override void apply(RunnerAbility ability) { ability.JumpSpeed += 8.0f; }
public void applyAllBuffs(RunnerAbility ability) { foreach (Buff b in buffs) { b.apply (ability); } }