Click here to Skip to main content
15,508,376 members

Comments by Joana Gonçalves 2022 (Top 7 by date)

Joana Gonçalves 2022 21-Apr-22 4:59am View    
but aren't the step by step youtube videos supposed to help?
Joana Gonçalves 2022 21-Apr-22 4:13am View    
I'm still trying to understand the code syntax
Joana Gonçalves 2022 20-Apr-22 12:28pm View    
I just got here, stop being rude to me
Joana Gonçalves 2022 20-Apr-22 12:26pm View    
(45,51):error CS0119:"ForceModeD" é um tipo que não é válido para o contexto
especificado (47,63):error CS0113:"Impulse" não existe no contexto atual
Joana Gonçalves 2022 20-Apr-22 12:23pm View    
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class moviment1 : MonoBehaviour
{
public float Speed;
public float JumpForce;

public bool isJumping;
public bool doubleJump;

private Rigidbody2D rig;

// Start is called before the first frame update

void Start()
{

rig = GetComponent<rigidbody2d>();
}

// Update is called once per frame

void Update()
{
Move();
Jump();
}

// MOVE

void Move()
{
Vector3 movement = new Vector3(Input.GetAxis("Horizontal"), 0f, 0f);
transform.position += movement * Time.deltaTime * Speed;
}

// JUMP
void Jump()
{
if (Input.GetButtonDown("Jump") )
{
if(!isJumping)
{

rig.AddForce(new Vector2(0f, JumpForce), ForceMode2D,Impulse);
doubleJump = true;
}
else
{
if(doubleJump)
{
rig.AddForce(new Vector2(0f, JumpForce), ForceMode2D,Impulse);
doubleJump = false;
}

}

}

}
void OnCollisionEnter2D(Collision2D collision)
{
if(collision.gameObject.layer == 8)
{
isJumping = false;
}

}
void OnCollisionExit2D(Collision2D collision)
{
if(collision.gameObject.layer == 8)
{

isJumping = true;
}

}

}