У меня проблема с моим кодом, я начал изучать C #, поэтому я попытался написать код для некоторой игры (что-то вроде Geometry Dash).Я хочу, чтобы это движение и прыжок по клику.Я написал «код перемещения» и «код перехода по нажатию», но не работает.
Я пишу в Microsoft Visual Studio на C # и проектирую в Unity 2018.3.5f1.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Plaxercontrol2 : MonoBehaviour
{
public Rigidbody2D rb;
public Transform groundCheck;
public Transform startPosition;
public float groundCheckRadius;
public LayerMask whatIsGround;
private bool onGround;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update()
{
rb.velocity = new Vector2(3, rb.velocity.y);
onGround = Physics2D.OverlapCircle(groundCheck.position,
groundCheckRadius, whatIsGround);
if (Input.GetMouseButtonDown(0) && onGround)
{
rb.velocity = new Vector2(5, rb.velocity.x);
}
}
}
Теперь это только движение
и изображение Единства