MRW419
Explore posts from serversWhy is it not calling the OnCollisionEnter method?
"'cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(Rigidbody2D))]
public class Player : MonoBehaviour
{
// TODO: Reference to Rigidbody2D component should have class scope. public Rigidbody2D rigidbody2d; // TODO: A float variable to control how high to jump / how much upwards public float Jump = 10.0f; // force to add. public float force = 5.0f; // Start is called before the first frame update void Start() {
// TODO: Use GetComponent to get a reference to attached Rigidbody2D rigidbody2d = gameObject.GetComponent<Rigidbody2D>(); } // Update is called once per frame void Update() { // TODO: On the frame the player presses down the space bar, add an instant upwards if(Input.GetKeyDown(KeyCode.Space)) { OnCollisionEnter(Collision, other);
} // force to the rigidbody. } void OnCollisionEnter(Collision other) { if(other.gameObject.CompareTag("Ground")) { Vector3 jump = transform.up; GetComponent<Rigidbody2D>().AddForce(jump * force, ForceMode2D.Impulse); } } } "'
// TODO: Reference to Rigidbody2D component should have class scope. public Rigidbody2D rigidbody2d; // TODO: A float variable to control how high to jump / how much upwards public float Jump = 10.0f; // force to add. public float force = 5.0f; // Start is called before the first frame update void Start() {
// TODO: Use GetComponent to get a reference to attached Rigidbody2D rigidbody2d = gameObject.GetComponent<Rigidbody2D>(); } // Update is called once per frame void Update() { // TODO: On the frame the player presses down the space bar, add an instant upwards if(Input.GetKeyDown(KeyCode.Space)) { OnCollisionEnter(Collision, other);
} // force to the rigidbody. } void OnCollisionEnter(Collision other) { if(other.gameObject.CompareTag("Ground")) { Vector3 jump = transform.up; GetComponent<Rigidbody2D>().AddForce(jump * force, ForceMode2D.Impulse); } } } "'
11 replies
❔ I'm having trouble with my assigment and I need help understanding
I'm learning Unity in my game design class and in Unity it tells me i'm missing one semi-colon but where?
if (numOne > numTwo)
{
print("numOne is greater then numTwo");
}
else (numOne == numTwo)
{
print("numOne is equal to numTwo");
}
8 replies