P
P
Pavel2020-06-02 22:15:08
Unity
Pavel, 2020-06-02 22:15:08

Why doesn't this code compile?

I started to write my game but ran into a problem

Here is the problematic code :

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class hero : MonoBehaviour {

  Rigidbody2D rb;

  // Use this for initialization
  void Start(){
    rb = GetComponent<Rigidbody2D> ();
  }
  
  // Update is called once per frame
  void Update() {
    if (Input.GetKeyDown (KeyCode.Space)) {
      Jumping(); // Jump Method
    }
  }

  void FixedUpdate() {
    rb.velocity = new Vector2 (Input.GetAxis ("Horizontal") * 12f, rb.velocity.y); // Walking
  }

  void Jumping() {
    rb.AddForce (transform.up * 3f, ForceMode2D.Impulse); // Jump
  }
  void Loser() {
    SceneManager.LoadScene( SceneManager.GetActiveScene().name );
  }
  void OnCollisionEnter2D(Collision2D lose) {
    if (lose.gameObject.tag == "Enemy") {
      Loser();
    }
  }
}

error CS0246
how to solve

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GavriKos, 2020-06-02
@GavriKos

Code doesn't compile when it has errors. And the error usually indicates what is wrong.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question