Question by
odillon69 · Apr 17 at 07:15 PM ·
c#character controllerreset
how do i reset my jump counter?
i have a script that allows a player to jump but only three times and then they can no longer jump but i want to be able to reset this number back to three if they hit a certain block but everything i've tried doesn't work, anyone have any ideas?
jump script:
using UnityEngine; using System.Collections;
[RequireComponent(typeof(Rigidbody))] public class PlayerController : MonoBehaviour { public Vector3 jump; public float jumpForce = 12.0f; public int JumpsUsed = 0; public int JumpsAll = 3; public GameObject sfxSource;
public bool isGrounded;
Rigidbody rb;
void Start()
{
rb = GetComponent<Rigidbody>();
jump = new Vector3(0.0f, 12.0f, 0.0f);
sfxSource = GameObject.Find("SFXsource");
}
void OnCollisionStay()
{
isGrounded = true;
}
void Update()
{
if (Input.GetKeyDown(KeyCode.UpArrow) && isGrounded && JumpsUsed < 3)
{
JumpsUsed ++;
rb.AddForce(jump * jumpForce, ForceMode.Impulse);
isGrounded = false;
sfxSource.GetComponent<soundManager>().PlayJumpSound();
}
if (Input.GetKeyDown(KeyCode.UpArrow) && isGrounded && JumpsUsed > 3)
{
return;
}
}
}
Comment
Answer by Turnrp · Apr 17 at 07:33 PM
Try something like this
void OnCollisionEnter(Collision collision)
{
if(collision.gameObject.tag == BLOCKTAG)
{
JumpsUsed = 3;
}
}