I am trying to make pong, and right now i am working on collision detection. I tried all kinds of functions, like OnCollisionEnter, OnCollisionEnter2D, OnTriggerEnter, OnTriggerEnter2D. nothing seems to work.
using UnityEngine;
using System.Collections;
public class BallMovement : MonoBehaviour {
public float x;
public float y;
bool d;
Transform tf;
void Start () {
tf = GetComponent<Transform>();
d = false;
}
void Update () {
Move ();
}
void Move(){
if (d == true) {//i also tried just "if (d)", but still the same movement
x = x + 0.1f;
} else {
x = x - 0.1f;
}
Vector2 v = new Vector2 (x,y);
tf.position = v;
}
void OnCollisionEnter(Collision col){
Debug.Log("collided");
if (col.gameObject.tag == "P1C1") {
d = true;
Debug.Log("collided");
}
}
}
The debug says that the function is never called.