Unity 2D does not detect collisions
Hi! I have a 2D game which a ball jumps, but I can't detect when the ball touches the end floor.
Shpere Script: using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Sphere_Movement : MonoBehaviour { public Rigidbody2D myrigidbody; public float movespeed = 4f; public float jumpspeed = 7f; public Vector2 x_1; private bool isGrounded; public int tiempo_salto_max = 1; public float tiempo_salto; // Start is called before the first frame update void Start() { x_1 = new Vector2(movespeed, myrigidbody.velocity.y); tiempo_salto = 0; }
// Update is called once per frame
void Update()
{
tiempo_salto += Time.deltaTime;
myrigidbody.AddForce(x_1);
if (Input.GetMouseButton(0)&&tiempo_salto >= tiempo_salto_max)
{
Jump();
}
}
void Jump()
{
myrigidbody.velocity = new Vector2(myrigidbody.velocity.x/2, jumpspeed);
tiempo_salto = 0;
}
}
End Floor Script:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class collision_player : MonoBehaviour { // Start is called before the first frame update void Start() {
}
// Update is called once per frame
void Update()
{
}
void OnCollision2D(Collision2D other)
{
if (other.gameObject.name == "Player")
Debug.Log("muerto");
}
}
Please indent your code to format it correctly (4 more spaces on every line), and clarify your question
Your answer
![](https://koobas.hobune.stream/wayback/20220612214211im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Unable to stop animation upon collision (2d, animation, rigidbody) 0 Answers
How to check if a collider is Touching any other object 2 Answers
2D Collisions Not Working,2d Collision not working? 0 Answers
Unity Collider2D is causing the game object to disappear upon collision? 1 Answer
OnTriggerEnter not being called 2 Answers