Ich habe einen Code geschrieben, um meinen Player zu steuern. Die Jump + Jump Animation (zusammen mit den Kleidungs- und Haaranimationen) spielt, wenn der Charakter die Leertaste berührt und wenn der Spieler von einer Plattform fällt.Double Jump funktioniert nicht
Mein Doppelsprung funktioniert nicht. Mein Spieler kann nur einmal springen. Kann jemand sehen, warum das nicht funktioniert?
using UnityEngine;
using System.Collections;
public class playerController : MonoBehaviour {
private Animator anim;
public Vector3 moveForward = new Vector3(1,0,0);
private float speed = 4;
private bool isGrounded;
private Rigidbody rb;
private bool doubleJump;
// Use this for initialization
void Start() {
rb = GetComponent<Rigidbody>();
anim = GetComponent<Animator>();
doubleJump = true;
}
// Update is called once per frame
void Update() {
transform.Translate(Vector3.forward * speed * Time.deltaTime);
if(isGrounded) {
if(Input.GetKeyDown("space")) {
if(isGrounded)
{
rb.velocity = new Vector3(10, 15, 0);
anim.Play("rig|Character_ActionsJUMP", -1, 0f);
anim.Play("Dress_Armature |Jump", 1, 0f);
anim.Play("Hair_Armature|Jump", 0, 0f);
isGrounded = false;
}
else if (!isGrounded && doubleJump) {
rb.velocity = new Vector3(10, 15, 0);
anim.Play("rig|Character_ActionsJUMP", -1, 0f);
anim.Play("Dress_Armature |Jump", 1, 0f);
anim.Play("Hair_Armature|Jump", 0, 0f);
doubleJump = false;
}
}
}
} //endOFUpdate
void OnCollisionEnter(Collision other) {
if(other.gameObject.tag == "Ground") {
isGrounded = true;
doubleJump = true;
anim.Play("rig|Character_Run", -1, 0f);
anim.Play("Dress_run", 1, 0f);
anim.Play("Hair_Armature|run", 0, 0f);
}
}//endOfOnCollion
void OnCollisionExit(Collision other) {
if(other.gameObject.tag == "Ground") {
isGrounded = false;
}
if(!isGrounded) {
anim.Play("rig|Character_ActionsJUMP", -1, 0f);
anim.Play("Dress_Armature |Jump", 1, 0f);
anim.Play("Hair_Armature|Jump", 0, 0f);
}
if(isGrounded) {
anim.Play("rig|Character_Run", -1, 0f);
}
}
}
Hallo ich Ihren Code versucht, und es ist nicht dass ich überhaupt springe jetzt! –
natürlich nicht, dieser Code war ein Beispiel, ich kann den tatsächlichen Code bearbeiten, wenn Sie möchten, ich benutzte den Code dort hypothetisch! –
Sorry, ich bin nur ein Anfänger. Wenn Sie den Code bearbeiten könnten, wäre es so hilfreich! Vielen Dank :) –