Simple scripting problem
Why this doesnt work? It wont write the text from Debug.log... Script
public bool check = false;
void Update()
{
if(check == true)
{
Debug.Log("Checked");
}
}
void OnCollisionEnter2D()
{
If(coll.gameObject.tag == "Enemy")
{
check = true;
}
}
Answer by Bunny83 · Feb 23, 2018 at 10:26 PM
This snippet alone has already two issues which would make it to not compile. First your if statement inside OnCollisionEnter2D starts with an uppercase "I". It has to be if
. Your "OnCollisionEnter2D" method is missing the Collision2D parameter "coll".
In case those were just typos here on UA the only other condisions we can't check are:
Is the script attached to an object with any Collider2D?
Does the object where this script is attached to has a Rigidbody2D component?
Are you sure that the object you collided with is tagged "Enemy"?
Your answer
Follow this Question
Related Questions
Enabling & Disabling Script via On Click 1 Answer
How to change the Bool for only a single prefab GameObject creating with Instantiate? 2 Answers
How Can i Get This bool to work? Just need someone willing to explain. 2 Answers
PLEAASEE I NEED HELP!!! How to turn Mesh Renderer of cubes on and off by pushing buttons? 1 Answer
Script Variable not transfering 0 Answers