Resolved Error CS1061 upon trying to use deltaTime for a game jump.

Nanashi

New member
Joined
Dec 29, 2022
Messages
4
Programming Experience
Beginner
C#:
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
    [SerializeField] private float speed;

    private Rigidbody2D body;
    private float moveInput;

    private bool isGrounded;
    public Transform feetPos;
    public float checkRadius;
    public float jumpForce;
    public LayerMask whatisGround;

    private float jumpTimeCounter;
    public float jumpTime;
    private bool isJumping;

    private void Awake()
    {
        body = GetComponent<Rigidbody2D>();
    }

    private void FixedUpdate()
    {
        moveInput = Input.GetAxis("Horizontal");
        body.velocity = new Vector2(moveInput * speed, body.velocity.y);
    }

    private void Update()
    {
     
        isGrounded = Physics2D.OverlapCircle(feetPos.position, checkRadius, whatisGround);

        if (isGrounded == true && Input.GetKeyDown(KeyCode.Space))
        {
            isJumping = true;
            jumpTimeCounter = jumpTime;
            body.velocity = Vector2.up * jumpForce;
        }
        if (Input.GetKey(KeyCode.Space) && isJumping == true)
        {
            if(jumpTimeCounter > 0)
            {
                body.velocity = Vector2.up * jumpForce;
                jumpTimeCounter -= jumpTime.deltaTime;
            } else
            {
                isJumping = false;
            }
           
        }
        if (Input.GetKeyUp(KeyCode.Space))
        {
            isJumping = false;
        }
    }
}
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

I'm beginner and trying to have an object jump in Unity. But the deltaTime comes back with a CS1061 error and have had trouble finding any prev thread that explains what I'm doing wrong. Any help is appreciated.
 
Last edited by a moderator:
jumpTime is a floating point number. It does not expose a deltaTime property.

Perhaps give us a link to the tutorial you are using to write the code above. We might be able to tell you where that deltaTime comes from and what to do with it.
 
jumpTime is a floating point number. It does not expose a deltaTime property.

Perhaps give us a link to the tutorial you are using to write the code above. We might be able to tell you where that deltaTime comes from and what to do with it.
 
jumpTime is a floating point number. It does not expose a deltaTime property.

Perhaps give us a link to the tutorial you are using to write the code above. We might be able to tell you where that deltaTime comes from and what to do with it.
he adds deltaTime around the 6-7 minute mark of video. Thanks!
 
Look closer at video at 6:27. He typed in Time.deltaTime, not jumpTime.deltaTime.
 
The tutorial was jumping up and down a lot and was hard to keep track.
I'm glad I'm not the only one who was thinking this guy had to lay off the cocaine or stop getting the double quad expresso.
 
Back
Top Bottom