Hello, I am working with my friend on a 2D Game and while I was working on the wall jumping and sliding I got this error: “error CS1061: ‘float’ does not contain a definition for ‘time’ and no accessible extension method ‘time’ accepting a first argument of type ‘float’ could be found (are you missing a using directive or an assembly reference?)”
Here is the Video:
Here is the Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TwoDemetionalMove : MonoBehaviour
{
// 2D Movement
private float horizontal;
private float speed = 8f;
private float jumpingPower = 16f;
private bool isFacingRight = true;
//Dashing
private bool canDash = true;
private bool isDashing;
private float dashingPower = 24f;
private float dashingTime = 0.2f;
private float dashingCooldown = 1f;
//Wall Jump
public float wallJumpTime = 0.2f;
public float wallSlideSpeed = 0.3f;
public float wallDistance = 0.5f;
bool isWallSliding = false;
RaycastHit2D wallCheckHit;
float jumpTime;
float mx = 0f;
bool isGrounded = true;
[SerializeField] private Rigidbody2D rb;
[SerializeField] private Transform groundCheck;
[SerializeField] private LayerMask groundLayer;
[SerializeField] private TrailRenderer tr;
private void Update()
{
if (isDashing)
{
return;
}
horizontal = Input.GetAxisRaw("Horizontal");
if (Input.GetButtonDown("Jump") && IsGrounded())
{
rb.velocity = new Vector2(rb.velocity.x, jumpingPower);
}
if (Input.GetButtonUp("Jump") && rb.velocity.y > 0f)
{
rb.velocity = new Vector2(rb.velocity.x, rb.velocity.y * 0.5f);
}
if (Input.GetKeyDown(KeyCode.LeftShift) && canDash)
{
StartCoroutine(Dash());
}
Flip();
}
private void FixedUpdate()
{
if (isDashing)
{
return;
}
rb.velocity = new Vector2(horizontal * speed, rb.velocity.y);
//WallJump
if (isFacingRight)
{
wallCheckHit = Physics2D.Raycast(transform.position, new Vector2(wallDistance, 0), wallDistance, groundLayer);
} else
{
wallCheckHit = Physics2D.Raycast(transform.position, new Vector2(-wallDistance, 0), wallDistance, groundLayer);
}
if (wallCheckHit && !isGrounded && mx != 0)
{
isWallSliding = true;
jumpTime = Time.time + wallJumpTime;
}
else if (jumpTime < jumpTime.time)
{
isWallSliding = false;
}
if (isWallSliding)
{
rb.velocity = new Vector2(rb.velocity.x, Mathf.Clamp(rb.velocity.y, wallSlideSpeed, float.MaxValue));
}
}
private bool IsGrounded()
{
return Physics2D.OverlapCircle(groundCheck.position, 0.2f, groundLayer);
}
private void Flip()
{
if (isFacingRight && horizontal < 0f || !isFacingRight && horizontal > 0f)
{
isFacingRight = !isFacingRight;
Vector3 localScale = transform.localScale;
localScale.x *= -1f;
transform.localScale = localScale;
}
}
private IEnumerator Dash()
{
canDash = false;
isDashing = true;
float originalGravity = rb.gravityScale;
rb.gravityScale = 0f;
rb.velocity = new Vector2(transform.localScale.x * dashingPower, 0f);
tr.emitting = true;
yield return new WaitForSeconds(dashingTime);
tr.emitting = false;
rb.gravityScale = originalGravity;
isDashing = false;
yield return new WaitForSeconds(dashingCooldown);
canDash = true;
}
}