Collision2d not working- With Screenshots
Okay, so I have these two gameobjects and I want the health of 1 to decrease from the Player on collision with the enemy. Here is the code:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class collision : MonoBehaviour {
public progress Progress;
void Start(){
GameObject.FindGameObjectWithTag("HealthBar").GetComponent<progress>();
}
void OnCollisionEnter2d(Collision2D coll){
if (coll.gameObject.tag == "box") {
Progress.curHealth -= 1;
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Can I edit and add code after Unity3d project is ported to IOS? 0 Answers
What is the best way to test multiplayer games in Unity? 0 Answers
Errors With Game Over Script 1 Answer
How would I best display my list as images 0 Answers
Why is this error coming up when the cameraFP variable IS assigned? 0 Answers