UnityNinja Community
Would you like to react to this message? Create an account in a few clicks or log in to continue.

UnityNinja CommunityLog in

UnityNinja - Video Game Development Community, including Resources, Forums, Marketplace & More.


descriptionmy jump doesnt work? Emptymy jump doesnt work?

more_horiz
jump script

Code:

using UnityEngine;
using System.Collections;

public class Bounce : MonoBehaviour {

   float atbTime;
   float currentatbTime;
   float perc = 1;

   Vector3 startPos;
   Vector3 endPos;
   
   bool firstInput;
   public bool justJump;
   
   // Update is called once per frame
   void Update () {
       if (Input.GetButtonDown ("up") || Input.GetButtonDown ("down") || Input.GetButtonDown ("left") || Input.GetButtonDown ("right") || Input.GetButtonDown ("space")) {
         if(perc == 1)
         {
            atbTime = 1;
            currentatbTime = 0;
            firstInput = true;
            justJump = true;
         }
      }
      startPos = gameObject.transform.position;

      if(Input.GetButtonDown ("right") && gameObject.transform.position == endPos) {
         endPos = new Vector3(transform.position.x + 1, transform.position.y, transform.position.z);
      }
      if(Input.GetButtonDown ("left") && gameObject.transform.position == endPos) {
         endPos = new Vector3(transform.position.x - 1, transform.position.y, transform.position.z);
      }
      if(Input.GetButtonDown ("up") || Input.GetButtonDown ("space") && gameObject.transform.position == endPos) {
         endPos = new Vector3(transform.position.x, transform.position.y, transform.position.z + 1);
      }
      if(Input.GetButtonDown ("down") && gameObject.transform.position == endPos) {
         endPos = new Vector3(transform.position.x, transform.position.y, transform.position.z - 1);
      }
      if (firstInput == true) {
         currentatbTime += Time.deltaTime * 5;
         perc = currentatbTime / atbTime;
         gameObject.transform.position = Vector3.Lerp (startPos, endPos, perc);
         if(perc > 0.8) {
            perc = 1;
         
         }
         if(Mathf.Round(perc) == 1) {
            justJump = false;
         }
      }
   }
}

animation controller script

Code:


using UnityEngine;
using System.Collections;

public class animController : MonoBehaviour {

   Animator anim;
   public GameObject thePlayer;

   // Use this for initialization
   void Start () {
      anim = gameObject.GetComponent<Animator> ();
   }
   
   // Update is called once per frame
   void Update () {
      Bounce bounceScript = thePlayer.GetComponent<Bounce> ();
      if (bounceScript.justJump == true) {
         anim.SetBool ("Jump", true);
      }
      else {
         anim.SetBool ("Jump", false);
      }
   }
}

descriptionmy jump doesnt work? EmptyRe: my jump doesnt work?

more_horiz
Working fine for me...

I did however change your Up Down and LEFT and RIGHT to respected WASD keys using Keycode.Space etc... 

not sure what we are missing here... 

do you have a screen y of your inspector holding the player bits and bobs#?
privacy_tip Permissions in this forum:
You cannot reply to topics in this forum
power_settings_newLogin to reply