Ppo_Ppo
-
Modifié le 29 janv. 2022 à 10:17
NHenry
Messages postés15048Date d'inscriptionvendredi 14 mars 2003StatutModérateurDernière intervention19 mars 2023
-
29 janv. 2022 à 12:01
Bonjour,
j'ai un problème je debute dans la programation pour Unity j'essaie de faire bouger mes premier personnages en 2D
mais à chaque fois mon code ne fonctionne pas et je bloque
voila mon code mais unity ne veut pas le lire a cause de cette erreur :
unity error cs0116 a namespace cannot directly contain members such as fields or methods
est ce que quelqu'un pourrait me corriger ? merci d'avance
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
private Rigidbody2D rb2D;
private float moveSpeed;
private float jumpForce;
private bool isJumping;
private float moveHorizontal;
private float moveVertical;
// Start is called before the first frame update
void Start()
{
rb2D = gameObject.GetComponent<Rigidbody2D>();
moveSpeed = 3f;
jumpForce = 60f;
isJumping = false;
}
// Update is called once per frame
void Update()
{
moveHorizontal = Input.GetAxisRaw("Horizontal");
moveVertical = Input.GetAxisRaw("Vertical");
}
}
void FixUpdate()
{
if(moveHorizontal > 0.1f|| moveHorizontal < -0.1f)
{
rb2D.AddForce( new Vector2(moveHorizontal * moveSpeed, 0f), ForceMode2D.Impulse);
}
}
EDIT : Ajout des balises de code (la coloration syntaxique). Explications disponibles ici : ICI