Okay so I have a code that I’ve made after a while of not doing anything. I just need to know why my OnCollisionExit() function is always returning zero. I’m up to the May 2018 update just in case anyone is wondering. I’ll provide the entire code just so you guys can have everything needed.
Thank you in advance!
My code is as follows:
.
.
.
.
.
.
.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class bridge : MonoBehaviour {
public GameObject player;
private float playerPosXPast;
private float playerPosZPast;
private float playerPosAlwaysX;
private float playerPosAlwaysZ;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
playerPosAlwaysX = player.transform.position.x;
playerPosAlwaysZ = player.transform.position.z;
}
void OnCollisionExit() {
float playerPosXnow = playerPosAlwaysX;
float playerPosZnow = playerPosAlwaysZ;
if ((playerPosXPast > playerPosXnow + 4) ||
(playerPosZPast > playerPosZnow + 4)) {
Destroy(gameObject);
}
Debug.Log(playerPosXPast + " = x now");
Debug.Log(playerPosZPast + " = z now");
}
void OnCollisionEnter() {
float playerPosXPast = player.transform.position.x;
float playerPosZPast = player.transform.position.z;
Debug.Log(playerPosXPast + " = x then");
Debug.Log(playerPosZPast + " = z then");
}
}