I have a boolean saying where a ball is going to go. When the ball hits an object, it chnages the variable and goes the other way. when it collides, the debug says it collided, but the bool isn’t changed.
using UnityEngine;
using System.Collections;
public class BallMovement : MonoBehaviour {
float x;
float y;
bool d;
Rigidbody rb;
void Start () {
rb = GetComponent<Rigidbody>();
}
void Update () {
if (d) {
Debug.Log ("true");
}
Move ();
}
void Move(){
if (d){
x = x + 0.1f;
} else {
x = x - 0.1f;
}
Vector2 v = new Vector2 (x,y);
rb.MovePosition (v);
}
void OnCollisionEnter(UnityEngine.Collision col){
Debug.Log("collided");
if (col.gameObject.name == "P1C1") {
d = true;
Debug.Log("collided");
}
}
}
the debug never says “true”, and the ball doesn’t change direction. I will eventually use an integer for d.