Answer the question
In order to leave comments, you need to log in
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();
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question