Question by
VoKhab · May 05, 2019 at 10:24 PM ·
c#unityeditor
OnCollisionExit always showing 0
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");
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612200759im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Lookin for a windows Internet check 0 Answers
ForcedScopedThreadAttach 0 Answers
Comparing a gameObject's source prefab with a prefab 0 Answers
How to i use get key to use the turn? 1 Answer
Change starting scene based on file 0 Answers