Times hit not registering

I have tried multiple times and ways to get this to work, even starting completely over on the project and remaking from scratch. I can not get the collision to work. Secondtry is my script that I made over after deleting the original brick script that didn’t work. I have checked every letter. Here is my stuff…

using UnityEngine;
using System.Collections;

public class secondtry : MonoBehaviour {
	
	public int maxHits;
	public int timesHit;
	
	// Use this for initialization
	void Start () {
		timesHit = 0;
		
	}
	
	void Update(){
		
	}
	
	void onCollisionEnter2D (Collision2D col) {
		Debug.Log ("hit");
		timesHit++;
		maxHits--;
		
	}
}

My ball script

using UnityEngine;
using System.Collections;

public class Ball : MonoBehaviour {

	public Paddle paddle;
	private bool has_started = false;
	private Vector3 paddleToBallVector;

	void Start(){
		paddleToBallVector = this.transform.position - paddle.transform.position;
		
	}

	// Update is called once per frame
	void Update () {
		if(!has_started){
			this.transform.position = paddle.transform.position + paddleToBallVector;
			
			if (Input.GetMouseButtonDown(0)){
				has_started = true;
				this.rigidbody2D.velocity = new Vector2(5f,10f);
			}
		}
	}
}

Inspector on my 1 hit

Inspector on my ball

I’m nervous that is something simple, but I have spent to many hours trying to find it. I did mess with my gravity settings, there are currently at -5.

1 Like

Hi,

Cases sensitivity is your issue here.

Rename your method onCollisionEnter2D to OnCollisionEnter2D.

Hope this helps :slight_smile:

Man, I’m glad it’s simple, but that is frustrating. Thanks for all your help. I guess all these simple mistakes will start to teach me. Thanks @Rob

1 Like

It’s an easy mistake to make, no biggy.

Just remember about the case-sensitivity, that applies to any classes used in Unity, the ones you write yourself and C# in general.

The Unity documentation website will have theirs documented as they should appear in your code, and for C# in general you could turn to Microsoft docs. For you own code, I would recommend following their existing naming conventions also, e.g. PascalCase for classes, methods, properties, camelCase for variables.

The more code you write in this way, the more something that doesn’t quite follow that standard may stand out and then you’ll be answering these questions for other people here too :slight_smile:

Always happy to help :slight_smile:

Incidentally, is it working now?

Its working great.

1 Like

Great! Glad you can move forward again :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.